Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remote origin already exists on 'git push' to a new repository

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.

like image 392
uzumaki naruto Avatar asked Aug 03 '09 11:08

uzumaki naruto


People also ask

How do I push a new git repository remote?

To push the commit from the local repo to your remote repositories, run git push -u remote-name branch-name where remote-name is the nickname the local repo uses for the remote repositories and branch-name is the name of the branch to push to the repository. You only have to use the -u option the first time you push.

How do I get to my local repository and remove the existing origin remote?

We can use git remote -v to view all the remotes of our local repository. For example, we have set two remotes, origin and upstream . We use the command git remote rm followed by the remote name to remove a remote. It removes upstream from the git remote list.

Can I have two origins in git?

You can have as many remote repositories as you want, but you must give them different names. The repository name is different in this case. Is the the word "origin" a name that can be changed?


2 Answers

You are getting this error because "origin" is not available. "origin" is a convention not 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 

See the manual:

http://www.kernel.org/pub/software/scm/git/docs/git-remote.html

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 
like image 73
MrHus Avatar answered Sep 22 '22 18:09

MrHus


The previous solutions seem to ignore origin, and they only suggest to use another name. When you just want to use git push origin, keep reading.

The problem appears because a wrong order of Git configuration is followed. You might have already added a 'git origin' to your .git configuration.

You can change the remote origin in your Git configuration with the following line:

git remote set-url origin [email protected]:username/projectname.git 

This command sets a new URL for the Git repository you want to push to. Important is to fill in your own username and projectname

like image 25
Hoetmaaiers Avatar answered Sep 18 '22 18:09

Hoetmaaiers