Skip to main content
DevOps Insightsguides & answers

Git · troubleshooting

error: remote origin already exists

The repository already has a remote called origin, often because you cloned it or ran the setup steps twice, so git remote add origin refuses. Change its URL with git remote set-url origin URL, or add the new remote under another name.

Reproduced on Git 2.50.1, . Where the text says “reproduced”, the behaviour was run on that version, not taken from documentation.

First published

New to this? Read what is actually happening first, then come back to the steps.

On this page · 9 sections

Before you start

  • A terminal in the repository.

Run this first

step 1 of 1
git remote -v

Look for origin and where it points

Lists every remote with its fetch and push URL.

Work out which cause you have

A few questions to narrow the list. Every answer ends in a command that confirms or rules the cause out — this cannot see your cluster, so nothing here is a certainty until you have checked.

Narrow it down

0 answered · nothing is sent anywhere

What did you want to do?

Cause space

2 of 2 still possible

  • origin was set by git clone or an earlier setup stepCommon
  • You want a second remote, not a replacementOccasional

Nothing ruled out yet. Answer the question above and the branches your answer eliminates will strike through here.

Or diagnose it manually

In this order. The first command usually contains the whole answer.

  1. Step 1

    git remote -v

    Lists every remote with its fetch and push URL.

    Look for origin and where it points

Every cause, and how to fix it

Ordered by how often each one turns out to be the answer.

origin was set by git clone or an earlier setup step

Common

The repository was cloned, or the new-repository instructions were run twice, so origin exists already.

Confirm

git remote -v

An origin line, possibly with a different URL from the one you are adding

Fix

  • To change where origin points: git remote set-url origin NEW_URL, then git remote -v to check.
  • If origin already has the right URL, skip the add and push: git push -u origin main.
git remote set-url origin NEW_URL && git remote -v

Reproduced on Git 2.50.1.

You want a second remote, not a replacement

Occasional

Working with a fork and the original, or mirroring to a second host: both need a remote, under different names.

Confirm

git remote

origin listed, and a second repository you also need

Fix

  • Add the second under its own name: git remote add upstream URL, then git fetch upstream.
  • Or rename the existing one first: git remote rename origin old, then git remote add origin NEW_URL.

Understanding it properly

Skip this if you are mid-incident — the working part of the page is above. Worth reading afterwards, because understanding the mechanism is what stops the next one.

In plain terms

A remote is a short name, such as origin, for the address of another copy of the repository. git remote add creates a new name, and Git will not create one that already exists. Cloning sets origin for you, so copying the 'add origin' line from a new-repository page into a cloned repository always hits this.

Words used on this page

Remote
A named address of another copy of the repository, used by fetch, pull and push.
origin
The conventional name for the main remote; git clone creates it automatically.
upstream
A common name for a second remote, such as the original repository you forked from.
What is actually happening

Reproduced on Git 2.50.1: after git clone, git remote -v already listed origin, and git remote add origin URL printed error: remote origin already exists. and exited with status 3.

If you meant to point origin somewhere else (a new GitHub repository, SSH instead of HTTPS), git remote set-url origin URL changes it in place.

If you meant to keep both, give the new one another name: git remote add upstream URL. Or rename the old one first with git remote rename origin old, then add the new origin; both worked in the reproduction.

How to tell this is your problem
WhereWhat you see
git remote add origin URLerror: remote origin already exists.
git remote -vorigin is already listed, with the URL you cloned from

How to know it is actually fixed

  • git remote -v shows origin (and any second remote) with the URLs you intended.
  • git push -u origin main reaches the intended repository.

Stopping it happening again

  • After cloning, skip the git remote add origin step from new-repository instructions; clone already did it.
  • Use git remote set-url, not remove and add, when only the address changes.

Security considerations

  • Check the URL you set: git remote -v shows where pushes will go, and a wrong remote can publish private code to the wrong place.
  • Do not put a password or token inside the remote URL; it ends up in .git/config and shell history.

Sources

Behaviour described here is drawn from official documentation. Where a figure could not be confirmed on an official page it is attributed in the text rather than stated as canonical.

Did this get you to an answer?

No text box on purpose — please do not paste production logs anywhere

Something wrong or out of date? Report it