Change a Git remote URL
Update an existing remote, inspect separate fetch and push addresses, and resolve authentication issues after a repository move or protocol switch.
Use git remote set-url to change the address associated with an existing remote:
git remote -v
git remote set-url origin git@github.com:example/repo.git
git remote -v
This changes local configuration. It does not move the repository, rename branches, rewrite commits, or modify the working tree. Replace origin with the remote name you actually use.
Check both fetch and push destinations
A remote can have separate push URLs, and it can have multiple URLs. Inspect them explicitly:
git remote get-url --all origin
git remote get-url --push --all origin
# Change an explicitly configured push destination:
git remote set-url --push origin git@github.com:example/repo.git
Changing the normal URL does not replace a separately configured pushurl. The simple set-url form changes the first applicable URL; use the documented matching, add, and delete forms when managing multiple entries.
After checking the destination, fetch to test read access and update remote-tracking refs:
git fetch origin
A successful fetch does not prove that you have push permission. Fetch can update refs, tags, and object storage, although it normally leaves the checked-out branch and working files alone.
Switch between HTTPS and SSH
For GitHub, HTTPS Git authentication uses supported credentials such as a personal access token or a credential-manager flow, rather than an account password. SSH requires the corresponding public key and repository access.
git remote set-url origin https://github.com/example/repo.git
# Or use SSH:
git remote set-url origin git@github.com:example/repo.git
ssh -T git@github.com
GitHub's successful SSH authentication test reports that shell access is unavailable and can return a nonzero status. Read its message; do not treat this as an ordinary remote shell login.
Related operations
| Task | Command |
|---|---|
| Add a remote | git remote add upstream URL |
| Rename it | git remote rename origin old-origin |
| Remove its local configuration and tracking refs | git remote remove origin |
Removing a remote does not delete the hosted repository. For a fork, usually keep origin pointing to your fork and add the original repository as upstream instead of replacing origin.
Troubleshoot failures
No such remote: inspect git remote -v; use the existing name or add the missing remote.
Authentication or 403 failure: verify the URL, account, repository permissions, token restrictions, and any organization authorization requirements. Check for stale credentials before replacing them. Switching protocols changes the authentication mechanism; it does not grant access.
See git-remote and GitHub authentication.
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan