Back

Explore Courses Blog Tutorials Interview Questions
+15 votes
3 views
in DevOps and Agile by (29.3k points)
edited by

I have my project on GitHub at some location, [email protected]:myname/oldrep.git.

Now I want to push all my code to a new repository at some other location, [email protected]:newname/newrep.git.

I used the command:

git remote add origin [email protected]:myname/oldrep.git

but I am receiving this:

fatal: remote origin already exists.

closed

2 Answers

+14 votes
by (50.2k points)
edited by
 
Best answer

You are getting this error because "origin" is not available. "origin" is a name not a part of the command. 

"origin" is the local name of the remote repository.

For example, you could also write:

git remote add myorigin [email protected]:myname/oldrep.git  

git remote add testtest [email protected]:myname/oldrep.git

To remove a remote repository you enter:

git remote rm origin

Again "origin" is the name of the remote repository if you want to remove the "upstream" remote:

git remote rm upstream

For more git commands like this please go through the following link:

+14 votes
by (62.9k points)

METHOD1:

Since origin already exists remove it.

git remote rm origin

git remote add origin https://github.com/USERNAME/REPOSITORY.git

METHOD2:

By using the command git remote set-url, one can change existing remote repository URL:

If you're updating to use HTTPS

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

If you're updating to use SSH

git remote set-url origin [email protected]:USERNAME/REPOSITORY.git

If trying to update a remote that doesn't exist you will receive an error. So be careful of that.

METHOD3:

To rename an existing remote, use the git remote rename command. An existing remote name, for example, is the origin.

git remote rename origin startpoint

# Change remote name from 'origin' to 'startpoint'

To verify remote's new name:

git remote -v

by (29.3k points)
thanks, for the detailed explanation, and for quick understanding, I would prefer @yeshwanth.intelli answer.

Browse Categories

...