我有我的项目在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
但我所领受的是:
致命:远程源已经存在。
当前回答
前面的解决方案似乎忽略了起源,他们只是建议使用另一个名称。当你只想使用git push origin时,请继续阅读。
出现这个问题是因为Git配置顺序错误。你可能已经在你的.git配置中添加了一个“git origin”。
你可以在你的Git配置中使用下面的代码行更改远程原点:
git remote set-url origin git@github.com:username/projectname.git
这个命令为要推送的Git存储库设置一个新的URL。 重要的是填写您自己的用户名和项目名
其他回答
您需要检查原点,如果不存在则添加。
if ! git config remote.origin.url >/dev/null; then
git remote add origin git@github.com:john/doe.git
fi
创建文件check.sh,粘贴脚本,更新git存储库URL,然后运行。/check.sh。
如果你想在github中创建一个具有相同项目的新存储库,并且之前的Remote不允许你这样做,在这种情况下,首先删除github上的存储库,然后你只需要删除。git文件夹C:\Users\Shiva\AndroidStudioProjects\yourprojectname\。Git删除了这个文件夹(确保你点击了隐藏文件,因为这个文件夹是隐藏的)
同时点击android studio settings ->VersionControl中的minus(Remove)按钮 点击这里删除版本控制从android,然后你将能够创建新的存储库。
METHOD1 - - - >
因为原点已经存在,删除它。
git remote rm origin
git remote add origin https://github.com/USERNAME/REPOSITORY.git
METHOD2 - - - >
还可以通过->git remote set-url更改现有的远程存储库URL
如果您正在更新使用HTTPS
git remote set-url origin https://github.com/USERNAME/REPOSITORY.git
如果您正在更新以使用SSH
git remote set-url origin git@github.com:USERNAME/REPOSITORY.git
如果试图更新一个不存在的远程,您将收到一个错误。所以要小心。
METHOD3 - - - >
使用git remote rename命令重命名已存在的远程。 一个现有的远程名称,例如origin。
git remote rename origin startpoint
# Change remote name from 'origin' to 'startpoint'
验证远程的新名称->
git remote -v
如果刚接触Git,试试这个教程->
试试git教程
git remote rm origin
然后
git push -f
git remote rm origin
git remote add origin git@github.com:username/myapp.git