我有我的项目在GitHub上的一些位置,git@github.com:myname/oldrep.git。

现在,我想将所有代码推到其他位置的新存储库git@github.com:newname/newrep.git。

我使用命令:

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

但我所领受的是:

致命:远程源已经存在。


当前回答

我第一次使用Bitbucket时也遇到了同样的问题。

我的问题是我需要把origin这个词改成一些自定义的东西。我使用了应用程序的名称。所以:

git remote add AppName https://someone@bitbucket.org/somewhere/something.git

其他回答

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远程rm来源 Git remote -v 它不会显示任何存储库名称 Git远程添加源git@github.com:用户名/myapp.git Git push origin master 它将启动流程并创建新分支。 你可以看到你的作品被推送到github。

我第一次使用Bitbucket时也遇到了同样的问题。

我的问题是我需要把origin这个词改成一些自定义的东西。我使用了应用程序的名称。所以:

git remote add AppName https://someone@bitbucket.org/somewhere/something.git
git remote rm origin 

然后

git push -f 

下面的两个命令应该有助于设置。

git remote set-url origin https://github.com/USERNAME/NEW_REPO.git
    
git push --set-upstream origin main