How to Fix ‘fatal: remote origin already exists’ in Git and Linux

Connecting a local Git repository to a remote platform such as GitHub, GitLab, or Bitbucket is a standard developer workflow. You initialize your project, commit your files, and prepare to publish using the command git remote add origin <URL>. However, when the terminal responds with the error message: ‘fatal: remote origin already exists.’, Git blocks the addition of the new remote repository alias. This occurs because Git requires each remote tracking name within a single repository to be completely unique.

Why Does Git Show ‘remote origin already exists’?

In Git terminology, origin is not a special command or protocol; it is simply the conventional default nickname assigned to the primary remote server. This fatal error occurs under common development conditions:

  • Re-running Repository Setup Commands: Running the initial setup command twice in the same project directory.
  • Cloned Existing Repositories: If you cloned the repository via git clone, Git automatically created an origin alias pointing to the cloned source.
  • Fork or Migration Remotes: Attempting to point a project to a new GitHub organization or enterprise server while the original repository remote remains configured.
  • Template Repositories: Using a starter kit or scaffold that already contains a pre-configured .git metadata directory.

Step 1: Inspect Configured Remotes with git remote -v

Before modifying or deleting anything, verify where the current origin pointer is directed.

  1. Open your Linux terminal and navigate to your project directory:
    cd /path/to/your/repository
  2. List all currently configured remote connections and their target URLs:
    git remote -v
  3. The output will display the fetch and push endpoints for origin:
    origin  https://github.com/old-user/old-repo.git (fetch)
    origin  https://github.com/old-user/old-repo.git (push)

Step 2: Update the Existing Origin URL with git remote set-url

If you intended to change the target remote repository location, you do not need to add a new remote. Instead, update the existing origin URL.

  1. Use the set-url sub-command followed by the new target repository link:
    git remote set-url origin https://github.com/your-username/your-new-repo.git
  2. If you are using SSH authentication keys instead of HTTPS, enter:
    git remote set-url origin [email protected]:your-username/your-new-repo.git
  3. Verify that the URL has been updated:
    git remote -v
  4. Push your branch to the newly configured remote:
    git push -u origin main

Step 3: Remove the Existing Remote and Add a New One

If you prefer a clean setup or want to completely detach from the old remote connection, remove the existing origin pointer first.

  1. Remove the existing origin alias:
    git remote remove origin
  2. Now run your original add command without encountering the conflict:
    git remote add origin https://github.com/your-username/your-repo.git
  3. Confirm that the new endpoint is active by running git remote -v.

Step 4: Use a Different Remote Name (e.g. Upstream or Custom)

If you are contributing to an open-source project or maintaining a fork, you may want to keep the original remote while adding your personal repository.

  1. Leave origin intact and assign a descriptive alternate name such as upstream or personal:
    git remote add upstream https://github.com/original-owner/original-repo.git
  2. Inspect your dual remotes:
    git remote -v
  3. You can now fetch from upstream while pushing your personal changes to origin:
    git fetch upstream
    git push origin main

Step 5: Edit the .git/config File Directly

For complete control, you can review and edit Git’s raw configuration file directly in your terminal.

  1. Open the local repository configuration file using nano:
    nano .git/config
  2. Locate the section header labelled [remote "origin"]:
    [remote "origin"]
        url = https://github.com/example/repo.git
        fetch = +refs/heads/*:refs/remotes/origin/*
  3. Edit the url = string to point to your desired remote address, or remove the entire block if you wish to reset it completely.
  4. Save the file by pressing Ctrl + O, press Enter, and exit with Ctrl + X.

Understanding how Git manages remote aliases ensures you can easily inspect, reassign, or rename remotes whenever repository configurations change.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.