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

I have my project on GitHub at some location, git@github.com:myname/oldrep.git .

Now I want to push all my code to a new repository at some other location, git@github.com:newname/newrep.git .

I used the command:

git remote add origin git@github.com:myname/oldrep.git

but I am receiving this:

fatal: remote origin already exists.


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 git@github.com:myname/oldrep.git  
git remote add testtest git@github.com: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

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 git@github.com: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


如果您错误地将本地名称命名为“原产地”,则可以通过以下方式将其删除:

git remote rm origin
链接地址: http://www.djcxy.com/p/4626.html

上一篇: 在git中克隆远程存储库时无法解析主机github.com错误

下一篇: 在'git push'上,远程原点已经存在于一个新的仓库中