Push & pull problemsAlways fixable

Fix 'remote origin already exists'

git remote add origin fails with 'remote origin already exists' — what do I do?

If you’re seeing this error

fatal: remote origin already exists.
error: remote origin already exists.

You’re in the right place — the fix is below.

Short answer

This repository already has a remote called origin, usually because it was cloned or because you ran the same setup instructions twice. Check where it points with git remote -v. If it is wrong, change it with git remote set-url origin <url> rather than adding a second one.

quick fix
git remote -v
git remote set-url origin https://github.com/user/repo.git

Look first, then update the existing remote instead of adding another

Does this match your situation?

  • 'fatal: remote origin already exists.'
  • You pasted GitHub's 'push an existing repository' instructions into a folder you had cloned.
  • You are moving a project from one host to another.
  • You forked a repository and want to add the original as a second remote.

Step-by-step fix

  1. Look at what you already have

    Often origin is already correct and the error is harmless — the setup instructions simply assumed a folder that had never been cloned. Check before changing anything.

    step 1
    git remote -v
    git remote show origin
    
  2. Point origin somewhere else

    This is the right move when you are switching hosts, moving from HTTPS to SSH, or fixing a typo. It rewrites the URL in place and keeps every tracking relationship intact.

    step 2
    git remote set-url origin git@github.com:user/repo.git
    git remote -v
    
  3. Remove and re-add, if you would rather start clean

    Functionally the same as set-url for most purposes. Worth knowing, but set-url is preferable because it does not disturb the branch tracking configuration.

    step 3
    git remote remove origin
    git remote add origin https://github.com/user/repo.git
    git push -u origin main
    
  4. Add it under a different name instead

    Nothing forces you to have one remote. The standard fork arrangement keeps origin as your copy and adds the original project as upstream, so you can pull their changes without pushing to them by accident.

    step 4
    git remote add upstream https://github.com/original/repo.git
    git fetch upstream
    git remote -v
    
  5. Push to two places at once

    A single remote can have multiple push URLs — useful when mirroring a repository to a second host during a migration.

    step 5
    git remote set-url --add --push origin git@github.com:user/repo.git
    git remote set-url --add --push origin git@gitlab.com:user/repo.git
    git push origin main        # goes to both
    

Why this works

'origin' carries no special meaning in Git. It is simply the conventional name clone gives the URL it copied from, and a repository can have as many remotes as you like under any names you choose — each one just a stanza in .git/config holding a URL and a fetch refspec. git remote add refuses to overwrite an existing name for the same reason mkdir refuses to overwrite a directory: quietly replacing the address your work is pushed to is not something a command should do by accident. That is why set-url exists as the explicit way to say you really do mean to change it.

If that didn’t work

  • Inspect the raw config with git config --get-regexp '^remote\.' if the state looks inconsistent.
  • A half-removed remote can be cleared with git config --remove-section remote.origin.
  • After changing the URL, git fetch to confirm authentication still works.
  • Remote names are case-sensitive: Origin and origin are two different remotes.

How to stop it happening again

  • Run git remote -v before pasting any 'add a remote' instructions.
  • Use set-url to change an address and add only to introduce a genuinely new one.
  • Stick to the convention: origin is your copy, upstream is the project you forked.
  • When migrating hosts, change the URL rather than re-cloning — your branches and reflog stay put.

Commands used in this guide

git remote

Manage the named URLs your repository syncs with.

git config

Read and write Git settings for one repo, your user, or the whole machine.

git clone

Copy a remote repository, its full history and its branches, onto your machine.

git fetch

Download new commits from the remote without changing any of your files.

git push

Upload your commits to the remote repository.

Still stuck?

Search the full command reference and every other rescue guide — there are 76 of them, covering everything from detached HEAD to force-push disasters.

Browse all guides →

Frequently asked questions

What does 'fatal: remote origin already exists' mean?

A remote named origin is already configured in this repository, and git remote add will not silently replace it. Run git remote -v to see where it points — if it is already correct, there is nothing to fix.

How do I change the URL of an existing remote?

git remote set-url origin <new-url>. It updates the address in place and leaves your branch tracking configuration alone, which is why it is preferred over removing and re-adding.

Should I remove origin or just change its URL?

Change it. Removing and re-adding achieves the same end but discards nothing useful and risks leaving branches with stale tracking configuration. set-url is the safe, boring option.

What is the difference between origin and upstream?

Both are just names. The convention with forks is that origin is your own copy — the one you push to — and upstream is the original project you fetch from to stay in sync. Git treats them identically; only the convention gives them meaning.

Can a Git repository have more than one remote?

Yes, as many as you like. git remote add <name> <url> for each, and git fetch --all to update them together. You can even give one remote several push URLs so a single push mirrors to two hosts.

Related rescue guides

← All Git Rescue guides