The “origin” keyword is commonly used to describe the central source of a Git repository. If you try to add a remote called “origin” that already exists, you will encounter the “fatal: remote origin already exists” error.
In this guide, we discuss the cause of and the solution to the fatal: remote origin already exists
, with reference to an example. Let’s get started.
fatal: remote origin already exists
The Git fatal: remote origin already exists
error indicates you are trying to create a remote with the name “origin” when a remote with this name already exists. This error is common if you have forgotten to set up a repository and are following setup instructions again. You may also see this error if you try to change the URL of the “origin” remote repository by using the git remote add command.
To solve this error, you should first check if the current remote associated with the “origin” keyword has the correct URL. You can do this using the git remote -v command:
git remote -v
You will see a list formatted like this:
origin https://github.com/career_karma_tutorials/git (fetch) origin https://github.com/career_karma_tutorials/git (push)
If the “origin” URL does not match the URL of your remote repository to which you want to refer, you can change the remote URL. Alternatively, you can remove the remote and set a new remote URL with the name “origin”.
An Example Scenario
We have a repository called “git” and we want to change the origin from:
https://github.com/career_karma_tutorials/git
The new origin should use the URL:
https://github.com/career_karma_tutorials/git_tutorials
To do so, we use the git remote add command, which adds a new remote to a repository:
git remote add origin https://github.com/career_karma_tutorials/git_tutorials
This command returns an error:
fatal: remote origin already exists.
Git is telling us that the “origin” remote already exists.
The Solution
We cannot add a new remote using a name that is already in use, even if we specify a new URL for the remote. In this case, we have tried to create a new remote called “origin” even though one exists. To solve the error, we must remove the existing remote called “origin” and add a new one or change the URL of the existing remote.
To remove the existing remote and add a new one, we can set a new URL for our remote:
git remote set-url origin https://github.com/career_karma_tutorials/git_tutorials
This is the preferred method because we can change the URL associated with our remote in one command. There is no need to remove the old origin and create a new one because the set-url command exists.
Alternatively, we can remove our “origin” remote and create a new one with our new URL:
git remote rm origin git remote add origin https://github.com/career_karma_tutorials/git_tutorials
This removes our existing “origin” remote and replaces the remote with a new one called “origin”, using the URL we have specified. But, this method uses two commands instead of the one that we used earlier.
Conclusion
The Git fatal: remote origin already exists
error is caused by creating a remote called “origin” when one already exists. To fix this error, replace the URL of your existing origin using the git remote set-url command. You can also remove your existing remote called “origin” and replace it with a new one using the git remote add command.
Do you want to learn more about coding in Git? Take a look at our How to Learn Git guide. This guide is filled with learning resources to help you build upon your knowledge of Git.
About us: Career Karma is a platform designed to help job seekers find, research, and connect with job training programs to advance their careers. Learn about the CK publication.