How to Fix Git Error “Fatal: Remote Origin Already Exists”?

Photo of author

By admin

The fatal error is caused mostly when you try to create a link to the remote repository that we know as “origin”. But there is already a remote link with that same name configured. Don’t worry; there are several solutions to this problem that you can try to implement and resolve the issue if successfully applied. The quickest solution we can give you is to update the URL of that remote repository with “origin” and add it to the URL of the repository you are trying to connect to. And in that case, you won’t have to create a new repository with remote access with the same “origin” name. To do that, a simple command will work just fine, which is:

git remote set-url origin https://github.com/your/repository

But there are several other resolutions that you can try if this one doesn’t work out. And to get those resolved, you should follow this guide from start to finish and also find out what’s causing the Git Error “Fatal: Remote Origin Already Exists.”

Why are you seeing the Git Error “Fatal: Remote Origin Already Exists?”

When you try to execute the git remote add origin <SOME-URL>/<SOME-REPOSITORY-NAME>.git command and find the “fatal: remote origin already exists message”, you should know what you are dealing with. In general, understanding this error message isn’t that tough. Centralized VCS always contains a central server, but Git contains remote repositories that you have access to read, write, or both. These repositories are accessible through SSH or HTTP requests. But even when we call them remote repositories, they are not always located on remote machines. And local remote repositories are a thing. Let’s call remote repositories “remote.”

These remotes have their own unique titles so that we can identify them quickly. One repository can have multiple names as well. But two remote repositories should not have the same name. And when you attempt to add a remote that has the same name as another remote, you see this fatal error.

If you need to ensure that the remote named “origin” does exist, you should run this command:

git remote

It will show you a list of all the existing names for that repository. To get detailed information on this, add the verbose parameter with the remote command: git remote-v, which will show you the remotes with every name plus the URLs. But the word origin is not pre-set, and the remote’s name can be anything. For example, the remote’s name can be “cute,” and the error message will be fatal: “cute” already exists.

So, now you know why the fatal error in the remote shows up. Let’s look for solutions.

Resolving the Git Error “Fatal: Remote Origin Already Exists-

After the above explanation about why you might encounter the fatal error, you should also check for some solutions on how to fix the error. Different solutions are available to resolve the same problem depending on specific situations.

1. Remove the already Existing Remote

Origin is the wrong remote name to begin with. For example, you use Github to store your repositories, but you want to switch to a different service. Here are the steps that you need to follow in that case:

  1. Create a new repository from Github
  2. Visit your local repository and remove the existing “origin” repository
  3. Add the new repository instead and name it “origin”
  4. Push the code to the new origin remote.

If you can’t or mistakenly skip the second step, then git will show a “remote origin already exists” error. But you can remove the existing remote to resolve the problem:

git remote remove origin

But if this solution does not help, let’s take a look at other solutions as well.

2. Update the Remote’s URL

Now that you know how to remove a remote repository, you can easily create the right one. But now, you should also try to update the URL of the existing repository. But it can be true that removing a repository and updating its link with a new URL is creepy. But you can use a single command to get it right:

git remote set-url <REMOTE-NAME> <NEW-URL>

Even though the remote name is “origin”, you can work with any remote name. Here is a complete instance that includes both the URL and remote name:

git remote set-url origin https://github.com/git/git.git

3. Rename the Old Remote

Suppose you already have a remote named “origin” but you need to create a new one and, at the same time, keep the old one. To do that, you can follow this method. You just have to rename the existing remote before you try to add a new one. To do that, run this command:

git remote rename <old-name> <new-name>

If you want to rename your origin remote to cute, run this command:

git remote rename origin cute

And now you can add your origin remote like you would, and the “remote origin already exists” error will also be gone.

4. Let it Be

There are times your git repository shows the “remote origin already exists” error when you try to add an origin remote, especially while following a tutorial. If you run the command again and see the error message, chances are you have already executed the command, but you don’t remember doing so. But to recheck the situation, you can use the git command and the verbose option together like this: git remote -v.

This will show you the existing URL and its remotes. If the old remote has the same URL that the tutorial has provided you with, it means your repository is already available, and you don’t need to do anything further.

If you are still not sure what the remote tool represents, let’s check out the following section.

Conclusion: What does the Remote Tool Represent?

The Git remote tool has a number of commands that let you configure the remote files. In specific cases, commands like “add,” “rename, “remove, and “more” are used. For example, if you use the git remote add name > url https://github.com/username/remote-repository.

If you read the guide all over again, you will notice that we have given four methods to fix the Git Error “Fatal: Remote Origin Already Exists.” And since you already know what’s causing the error, you can try to fix it in a matter of seconds. But for further information, you can read the “git remote”, where you will find the formal documentation of Git repository errors. You can always Google some “fixing” commands that will help you get away from the issue, but this guide will help you resolve the problem from scratch. If you need more guides like this, feel free to check out our other posts.

Leave a Comment