Change where your repository pushes to
How do I change the remote URL of a Git repository?
Short answer
git remote set-url origin <new-url> repoints an existing remote. It's a purely local change — nothing on either server is touched — so it's the safe way to switch between HTTPS and SSH, move to a new host, or fix a URL after renaming the repository.
git remote set-url origin git@github.com:USER/REPO.git
Repoint origin — local only, nothing on the server changes
Does this match your situation?
- You renamed the repository or moved it to a different organisation.
- You want to switch from HTTPS to SSH (or back).
- You're migrating from GitHub to GitLab, or to a self-hosted server.
- You cloned someone's repo and now want to push to your own fork.
Step-by-step fix
See what you have now
Remotes have separate fetch and push URLs, so check both before changing anything.
step 1git remote -vPoint it somewhere new
This rewrites the URL in .git/config. Nothing is uploaded, downloaded or deleted, and your commits are untouched.
step 2git remote set-url origin git@github.com:USER/NEW-REPO.git git remote -v # confirm git fetch origin # verify it actually worksAdd a second remote instead of replacing
When you want to push to two places — say a fork and the original — add another remote rather than replacing origin. This is the standard setup for contributing to open source.
step 3git remote add upstream https://github.com/original/repo.git git remote -v git fetch upstreamRename or remove a remote
Names are arbitrary; origin is only a convention. Renaming is safe and sometimes clearer, especially in a fork workflow.
step 4git remote rename origin github git remote remove old-serverReconnect your branches if push complains
After a URL change your branches usually keep tracking origin fine. If Git says there's no upstream, set it explicitly on the next push.
step 5git push -u origin main
Why this works
A remote is nothing more than a named URL stored in .git/config, plus a set of remote-tracking refs cached locally. Changing the URL rewrites one line of a text file — that's why the operation is instant and completely reversible, and why it can't damage either the old or the new server. The commits live in your local object database regardless of which URL you happen to be pointing at.
How to stop it happening again
- Use SSH URLs on machines you own so a password or token change never breaks them.
- After transferring a repository on GitHub, update remotes in every clone — the old URL redirects, but not forever.
- In a fork workflow, keep the convention: origin is your fork, upstream is the original.
Commands used in this guide
Still stuck?
Search the full command reference and every other rescue guide — there are 76 of them, covering everything from detached HEAD to force-push disasters.
Browse all guides →Frequently asked questions
Does changing the remote URL affect my commits?
No. It edits one setting in .git/config. Your commits, branches and history are entirely local and unaffected, and neither the old nor the new server is contacted until you fetch or push.
How do I switch a repository from HTTPS to SSH?
git remote set-url origin git@github.com:USER/REPO.git. Confirm with git remote -v and test with git fetch. You'll need an SSH key registered on your account for it to authenticate.
What is the difference between origin and upstream?
They're just names. By convention origin is the repository you push to — typically your own fork — and upstream is the original project you fetch updates from. Git attaches no special meaning to either name.
Related rescue guides
git remote add origin fails with 'remote origin already exists' — what do I do?
This repository already has a remote called origin, usually because it was cloned or because you ran the same setup instructions twice. Check where it points with git remote -v. If it is wrong, change it with git remote set-url origin <url> rather than adding a second one.
Read the fix →Always fixableHow do I sync my fork with the upstream repository?
Add the original repository as a remote called upstream, fetch it, then merge or rebase upstream/main into your main and push. GitHub's 'Sync fork' button does the same thing, but doing it locally gives you control when your fork has diverged.
Read the fix →Always fixableGit says 'Repository not found' but the URL is definitely right — why?
On a private repository, GitHub returns 'not found' rather than 'access denied' — so this usually means you are authenticated as the wrong account, not that the repository is missing. Check who you are with ssh -T git@github.com, and clear any stale credential your helper is replaying.
Read the fix →Usually recoverableHow do I delete a remote branch in Git?
git push origin --delete <branch> removes it from the server. Deleting it locally with git branch -d doesn't touch the remote at all, and other people keep seeing stale copies until they run git fetch --prune.
Read the fix →