If you’re a developer, version management systems and especially GitHub are probably the best thing that ever happened to you. However, as is always the case with programming and development, nothing goes without a random error popping up out of nowhere and GitHub is no exception.
In this article, we’re talking about the “error: remote origin already exists” problem, its causes and what you can do to fix the issue.
What causes this issue?
The error generally gets triggered when you clone a repository onto your local machine and try to change the pointing origin URL to your own local repository. The most common cause of the error is just a misconfiguration in terms of repository settings but it’s also often caused by the cloned repository having its own URL already configured.
How to fix this?
Here are three fixes you can try out.
Removing the existing remote origin
As mentioned before, one of the most common causes of the error is the fact that the local ‘origin’ isn’t available. Do keep in mind that ‘origin’ in this context refers to the local name of the remote repository. Just type the following command to remove the remote repository:
git remote rm origin
You can also remove the upstream remote using this command.
git remote rm upstream
Update the existing remote URL
Conflicting remote URLs also trigger this error. You can fix this by updating the remote URL using the command below.
git remote set-url origin [new URL]
Ensure that you’re pointing to a valid repository in the target URL otherwise, you’ll have to repeat this process except with a different error code.
Renaming the remote
If you don’t need to move the local repository around and it’s meant to stay offline, you can also try and simply rename the remote to something else so that you don’t have to worry about conflicting repositories between your local system and Github. Here’s how.
git remote rename origin [new name]
You can, of course, use the command to rename any other repositories as well. Simply replace ‘origin’ with the name of the target repository and you’re good to go.
Someone who writes/edits/shoots/hosts all things tech and when he’s not, streams himself racing virtual cars. You can reach out to Yadullah at [email protected], or follow him on Instagram or Twitter.