我有我的项目在GitHub上的一些位置,git@github.com:myname/oldrep.git。
现在,我想将所有代码推到其他位置的新存储库git@github.com:newname/newrep.git。
我使用命令:
git remote add origin git@github.com:myname/oldrep.git
但我所领受的是:
致命:远程源已经存在。
我有我的项目在GitHub上的一些位置,git@github.com:myname/oldrep.git。
现在,我想将所有代码推到其他位置的新存储库git@github.com:newname/newrep.git。
我使用命令:
git remote add origin git@github.com:myname/oldrep.git
但我所领受的是:
致命:远程源已经存在。
当前回答
如果您错误地将本地名称命名为“origin”,您可以使用以下方法删除它:
git remote rm origin
其他回答
当您忘记进行第一次提交时,也会发生这种情况。
您不必删除现有的“origin”远程,只需为远程添加使用“origin”以外的名称,例如。
Git远程添加github git@github.com:myname/oldrep.git
前面的解决方案似乎忽略了起源,他们只是建议使用另一个名称。当你只想使用git push origin时,请继续阅读。
出现这个问题是因为Git配置顺序错误。你可能已经在你的.git配置中添加了一个“git origin”。
你可以在你的Git配置中使用下面的代码行更改远程原点:
git remote set-url origin git@github.com:username/projectname.git
这个命令为要推送的Git存储库设置一个新的URL。 重要的是填写您自己的用户名和项目名
您得到这个错误是因为“origin”不可用。“origin”是一个约定,不是命令的一部分。“origin”是远程存储库的本地名称。
例如,你也可以这样写:
git remote add myorigin git@github.com:myname/oldrep.git
git remote add testtest git@github.com:myname/oldrep.git
详见说明书:
http://www.kernel.org/pub/software/scm/git/docs/git-remote.html
要删除远程存储库,请输入:
git remote rm origin
同样,如果需要的话,“origin”是远程存储库的名称 移除“上游”遥控器:
git remote rm upstream
我第一次使用Bitbucket时也遇到了同样的问题。
我的问题是我需要把origin这个词改成一些自定义的东西。我使用了应用程序的名称。所以:
git remote add AppName https://someone@bitbucket.org/somewhere/something.git