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 56 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
How 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 keeps saying authentication failed even though my password is correct — why?
GitHub stopped accepting account passwords over HTTPS in August 2021. You need a personal access token in place of the password, or better, switch the remote to SSH. If it worked yesterday, a cached old credential is usually the culprit — clear it and re-authenticate.
Read the fix →Always fixablegit clone or push fails with Permission denied (publickey) — how do I fix my SSH key?
The server didn't accept any key your SSH client offered. Either you have no key, the key isn't loaded into the agent, or its public half was never added to your account. Run ssh -T git@github.com to see exactly which keys are being tried.
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 →