This write-up will explain the solution for the existing remote origin error.
How Does the “remote origin already exists” Error Occur?
Users push their local code changes to the particular remote repository. Sometimes, they may want to push those changes to another remote repository. For this purpose, it is required to add another GitHub repository as a remote in the local repository. While adding a new remote, some errors like the “remote origin already exists” occurs. This is because the remote “origin” already exists in the current repository.
In the below image, it can be seen that when we add a remote origin, it gives an error:
Here, as you can see the “origin” already exists in the current repository:
How to Resolve the “remote origin already exists” Error?
To resolve the above-discussed error, different methods can be used:
- Method 1: Add Remote with a Different Name
- Method 2: Remove the Existing Remote Origin and Add New Remote
- Method 3: Set a New Remote URL
Method 1: Add Remote with a Different Name
To add a remote with a different name, utilize the “git remote add” command and specify the new desired remote name and remote repository URL:
Here, “myOrigin” is our new remote name:
Then, run the provided command to verify changes:
It can be observed that the new remote has been added:
Method 2: Remove the Existing Remote Origin and Add New Remote
First, type out the following command along with the existing remote name to remove it:
Here, “remote” is our existing remote name:
Then, add a new remote with the new remote repository URL:
Now, verify the newly added remote:
It can be seen that the new remote has been added successfully:
Method 3: Set a New Remote URL
To set the new URL for the already existing remote name, write out the provided command with the “set-url” option:
Then, ensure changes with the below-listed command:
As you can see the remote URL has been changed successfully:
We have explained different methods to resolve the “remote origin already exists” error.
Conclusion
To resolve the “remote origin already exists” error, different methods can be used, such as adding a remote with a different name, removing the existing remote origin and adding a new remote, or setting a new remote URL. This write-up explained the solution for the existing remote origin error.