How to fix "error: remote origin already exists"
Tested: we reproduced this error and confirmed the fix on Ubuntu 24.04 with Git 2.43.0, November 29, 2026.
Your repository already has a remote called origin, so git remote add origin refuses to create a second one. If you want origin to point somewhere new, change its URL instead:
git remote set-url origin https://github.com/you/project.git
git remote -v
We reproduced it with Git 2.43: git remote add origin on a repo that already had one printed error: remote origin already exists., and git remote set-url changed it without complaint. Some older guides and Git versions show the same message starting with fatal:.
Why it happens
- You cloned the repo, which sets
originto where you cloned from, then followed “push an existing repository” instructions that rungit remote add originagain. - You ran the setup commands twice.
- You’re moving the project to a new host (GitHub to GitLab, or a renamed repo).
Check where origin points now:
git remote -v
Fix: change the remote origin URL
To change where origin points, for example after you renamed the repository or moved it to another host, give it the new URL:
git remote set-url origin <new-url>
This keeps your branches and their tracking settings. Then push as usual: git push -u origin main.
Switch origin between HTTPS and SSH
The same command moves a remote from HTTPS to SSH or back, which is the usual fix when Git keeps asking for a password or a key:
git remote set-url origin git@github.com:you/project.git # SSH
git remote set-url origin https://github.com/you/project.git # HTTPS
SSH needs a key on your account; see how to generate an SSH key. HTTPS needs a personal access token or a credential manager instead of your password.
Fix: keep the old remote under another name
If you still need the old one (for example the original project you forked from):
git remote rename origin upstream
git remote add origin <new-url>
Fix: you wanted a second remote
If you forked a project and want both your copy and the original, keep origin and add the other under a new name. upstream is the usual name for the project you forked from:
git remote add upstream https://github.com/original/project.git
git fetch upstream
git remote -v
In our test git remote -v then listed both:
origin https://github.com/you/project.git (fetch)
origin https://github.com/you/project.git (push)
upstream https://github.com/original/project.git (fetch)
upstream https://github.com/original/project.git (push)
Fix: remove it and start over
git remote remove origin
git remote add origin <new-url>
Removing a remote doesn’t touch your commits or files; it only deletes the saved name and URL.
Confirm it worked
git remote -v shows the URL you expect for origin, and git push -u origin main goes to the right place. If that push says src refspec main does not match any, see our fix for that error.
FAQ
How do I see my current remote URL?
Run git remote -v. It lists each remote with its fetch and push URL.
Does removing a remote delete anything on GitHub?
No. git remote remove only deletes the saved name and URL in your local repo. The repository on GitHub and your local commits stay exactly as they were.
