GitHub “fatal: remote origin already exists” error – Fix

In this post, we will learn how to solve the “remote origin already exists error” in Github.

The “remote origin exists” error occurs when we try to create a link to a remote repository with the name “origin” when another repository is already configured with the same name in your local directory. Or when you clone a repository that already has a remote repository configured with the name “origin“.

To solve the remote origin already exits error we can:

  1. Update the URL of the Git remote using git remote set-url command.
  2. Remove the Git remote origin that already exists using the git remote remove command.
  3. Rename the Git remote origin using git remote rename command.

Update the git remote origin URL

First, check if you are connected to a remote origin repository using:

git remote -v

This will display the name of the git remote and its URLs.

origin https://github.com/username/reponame (fetch)
origin https://github.com/username/reponame (push) 

Now to update the git remote you have to get the new URL of the repository from github or bitbucket and update it using the git remote set-url command.

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

Here, the remote name is origin and the URL is your github repository URL address.

You can also call the new remote as github (you can give any name) instead of origin like this:

git remote set-url github https://github.com/user/reponame.git

Remove the remote origin from your repository locally

You can remove the git remote repository URL by using the git remote remove command.

First, check the existing git remote name using git remote -v. And then using the git remove command along with the git remote name (here origin), we can remove the remote repository connected to our local repository.

git remote remove origin

To verify if it is successfully removed, check by using git remote -v.

Now once it is removed, you can add the new git remote repository using git remote add command.

git remote add origin https://github.com/user/reponame.git

This will add the new git remote named “origin” to your local repository to communicate.

Rename Git Remote name

We can change the name of an existing remote using the git remote rename command.

You can get the current remote name using git remote -v command. This will display the git remote name like this.

origin https://github.com/username/reponame (fetch)
origin https://github.com/username/reponame (push) 

Here the remote name is “origin”.

Once we get the current name, we can rename it by running this command:

git remote rename origin gituser

The above command tells git to rename the current git remote from origin to gituser.


Related Topics:

Solved “No such remote origin” Git Error Fatal

[Fixed] GitHub “fatal: remote origin already exists” error

Fix – “fatal:refusing to merge unrelated histories” git error

Your Git Gateway backend is not returning valid settings – Fix

How to remove node_modules from github or bitbucket

Scroll to Top