GitHub
Git
remote origin
error fix
troubleshooting

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

bash
$ git remote add origin https://github.com/user/repo.git
fatal: remote origin already exists.

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:

bash
1# List remote names
2$ git remote
3origin
4
5# List remote names with URLs
6$ git remote -v
7origin  https://github.com/old-user/old-repo.git (fetch)
8origin  https://github.com/old-user/old-repo.git (push)
9
10# Show detailed info about a remote
11$ git remote show origin

Fix 1: Update the Existing URL (Most Common)

If you want to point origin to a different repository, update the URL:

bash
1# Change the remote URL
2$ git remote set-url origin https://github.com/new-user/new-repo.git
3
4# Verify the change
5$ git remote -v
6origin  https://github.com/new-user/new-repo.git (fetch)
7origin  https://github.com/new-user/new-repo.git (push)

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

bash
1# Current: HTTPS
2$ git remote -v
3origin  https://github.com/user/repo.git (fetch)
4
5# Switch to SSH
6$ git remote set-url origin [email protected]:user/repo.git
7
8# Verify
9$ git remote -v
10origin  [email protected]:user/repo.git (fetch)
11origin  [email protected]:user/repo.git (push)

Fix 2: Remove and Re-add the Remote

If you prefer to start fresh:

bash
1# Remove the existing remote
2$ git remote remove origin
3
4# Add the new remote
5$ git remote add origin https://github.com/user/new-repo.git
6
7# Verify
8$ git remote -v
9origin  https://github.com/user/new-repo.git (fetch)
10origin  https://github.com/user/new-repo.git (push)

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:

bash
1# Keep origin pointing to upstream
2$ git remote -v
3origin  https://github.com/original-author/repo.git (fetch)
4
5# Add your fork as a separate remote
6$ git remote add myfork https://github.com/your-user/repo.git
7
8# Or add the upstream as a named remote
9$ git remote add upstream https://github.com/original-author/repo.git
10
11# Now you have multiple remotes
12$ git remote -v
13myfork    https://github.com/your-user/repo.git (fetch)
14myfork    https://github.com/your-user/repo.git (push)
15origin    https://github.com/original-author/repo.git (fetch)
16origin    https://github.com/original-author/repo.git (push)
17upstream  https://github.com/original-author/repo.git (fetch)
18upstream  https://github.com/original-author/repo.git (push)

Common Multi-Remote Workflows

bash
1# Push to your fork
2$ git push myfork feature-branch
3
4# Pull from upstream
5$ git pull upstream main
6
7# Rename a remote
8$ git remote rename myfork fork

Fix 4: Rename the Existing Remote

If you want to keep the old remote but free up the origin name:

bash
1# Rename the current origin
2$ git remote rename origin old-origin
3
4# Add new origin
5$ git remote add origin https://github.com/user/new-repo.git
6
7# Verify both exist
8$ git remote -v
9old-origin  https://github.com/old-user/old-repo.git (fetch)
10old-origin  https://github.com/old-user/old-repo.git (push)
11origin      https://github.com/user/new-repo.git (fetch)
12origin      https://github.com/user/new-repo.git (push)

Setting Separate Fetch and Push URLs

Git supports different URLs for fetching and pushing:

bash
1# Set push URL to SSH (for authentication) while fetch stays HTTPS
2$ git remote set-url --push origin [email protected]:user/repo.git
3
4$ git remote -v
5origin  https://github.com/user/repo.git (fetch)
6origin  [email protected]:user/repo.git (push)

Common Pitfalls

  • Using git remote add when set-url is needed: If you want to change an existing remote's URL, use set-url, not add. add creates a new remote and fails if the name exists. set-url updates the URL of an existing remote.
  • Removing a remote without backing up the URL: git remote remove origin deletes the remote and all its tracking branches. If you forget the URL, check git reflog or .git/config backup. Consider using set-url instead to avoid losing tracking branches.
  • Confusing origin with upstream in fork workflows: By convention, origin points to your fork and upstream points to the original repository. Mixing these up causes pushes to go to the wrong repository. Always verify with git 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 add in the wrong directory: If you are in a subdirectory or a different repository, the command affects the wrong .git/config. Always verify your location with pwd and git remote -v before modifying remotes.

Summary

  • The error means a remote named origin already exists in your repository
  • Use git remote set-url origin <new-url> to update the URL (most common fix)
  • Use git remote remove origin then git remote add origin <url> to start fresh
  • Use git remote add <other-name> <url> to add a second remote alongside origin
  • Always verify your remotes with git remote -v after making changes

Course illustration
Course illustration

All Rights Reserved.