GitHub fatal remote origin already exists
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
The error fatal: remote origin already exists occurs when you run git remote add origin <url> in a repository that already has a remote named origin. Git only allows one remote per name. To fix it, either update the existing remote's URL with git remote set-url origin <new-url>, remove the old remote first with git remote remove origin, or add the new remote under a different name. This is one of the most common Git errors and is straightforward to resolve once you understand how Git remotes work.
When the Error Occurs
This happens because a remote named origin was already configured — typically when cloning a repository (which automatically sets origin) or from a previous git remote add command.
Checking Current Remotes
Before fixing, inspect what remotes already exist:
Fix 1: Update the Existing URL (Most Common)
If you want to point origin to a different repository, update the URL:
This is the most common fix when you are changing the repository URL (e.g., after transferring a repo, renaming it, or switching from HTTPS to SSH).
Switching from HTTPS to SSH
Fix 2: Remove and Re-add the Remote
If you prefer to start fresh:
git remote remove also deletes all remote-tracking branches and configuration associated with that remote.
Fix 3: Add Under a Different Name
If you need both remotes (e.g., forked workflow), add the second remote under a different name:
Common Multi-Remote Workflows
Fix 4: Rename the Existing Remote
If you want to keep the old remote but free up the origin name:
Setting Separate Fetch and Push URLs
Git supports different URLs for fetching and pushing:
Common Pitfalls
- Using
git remote addwhenset-urlis needed: If you want to change an existing remote's URL, useset-url, notadd.addcreates a new remote and fails if the name exists.set-urlupdates the URL of an existing remote. - Removing a remote without backing up the URL:
git remote remove origindeletes the remote and all its tracking branches. If you forget the URL, checkgit reflogor.git/configbackup. Consider usingset-urlinstead to avoid losing tracking branches. - Confusing
originwithupstreamin fork workflows: By convention,originpoints to your fork andupstreampoints to the original repository. Mixing these up causes pushes to go to the wrong repository. Always verify withgit remote -v. - Not updating after repository transfers or renames: When a GitHub repository is transferred to a new owner or renamed, the old URL may redirect temporarily but eventually stops working. Update your remote URL promptly with
git remote set-url. - Running
git remote addin the wrong directory: If you are in a subdirectory or a different repository, the command affects the wrong.git/config. Always verify your location withpwdandgit remote -vbefore modifying remotes.
Summary
- The error means a remote named
originalready exists in your repository - Use
git remote set-url origin <new-url>to update the URL (most common fix) - Use
git remote remove originthengit remote add origin <url>to start fresh - Use
git remote add <other-name> <url>to add a second remote alongsideorigin - Always verify your remotes with
git remote -vafter making changes

