Skip to content
Latchkey

git remote set-url: Usage, Options & Common CI Errors

git remote set-url rewrites the URL behind an existing remote name.

Swapping origin from SSH to an HTTPS token URL (or vice versa) is the most common CI use. Keep tokens out of logs and out of committed config.

What it does

git remote set-url replaces the fetch URL of a named remote (and optionally the push URL), without changing tracking config or fetched refs.

Common usage

Terminal
git remote set-url origin https://github.com/owner/repo.git
git remote set-url --push origin git@github.com:owner/repo.git
git remote set-url --add origin https://mirror.example.com/repo.git
git remote set-url origin https://x-access-token:${'$'}{TOKEN}@github.com/owner/repo.git

Options

FlagWhat it does
<name> <newurl>Set the fetch URL
--pushSet the push URL instead
--addAdd an extra URL rather than replace
--delete <pattern>Remove URLs matching a pattern

Common errors in CI

error: No such remote ‘origin’ - the remote name does not exist (fresh git init, or a different name). Add it first. Beware embedding a token in the URL: it can be written to .git/config and leak in logs; prefer a credential helper or http.extraheader, and never echo the URL.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →