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.gitOptions
| Flag | What it does |
|---|---|
| <name> <newurl> | Set the fetch URL |
| --push | Set the push URL instead |
| --add | Add 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
git remote add: Usage, Options & Common CI Errorsgit remote add registers a new named remote URL. Reference for -f, -t, --tags, and the "remote already exists…
git remote prune: Usage, Options & Common CI Errorsgit remote prune deletes local remote-tracking refs whose upstream branches are gone. Reference for --dry-run…
git remote: Usage, Options & Common CI Errorsgit remote manages the named connections to remote repositories. Reference for add, set-url, -v, remove, and…
git config --local: Usage, Options & Common CI Errorsgit config --local writes settings into a single repo’s .git/config. Reference for per-repo identity, scope p…