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

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

我使用命令:

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

但我所领受的是:

致命:远程源已经存在。


当前回答

您不必删除现有的“origin”远程,只需为远程添加使用“origin”以外的名称,例如。

Git远程添加github git@github.com:myname/oldrep.git

其他回答

您还可以在REPOHOME/中更改您希望推入的存储库名称。git /配置文件

(其中REPOHOME是存储库本地克隆的路径)。

您应该将远程存储库的名称更改为其他名称。

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

to

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

我认为这应该可行。

是的,这些用于存储库初始化和添加新的远程。只是换了个名字。

尝试删除第一个现有的起源,为了看到哪个现有的起源已经注册了bash,你可以启动下面的命令。

 git remote -v 

在您知道哪个版本的源已经注册到bash之后,您可以通过下面的命令来删除现有的源

git remote rm origin

一旦你删除了现有的原点,你可以在你的情况下通过以下命令添加新的原点。

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

一旦你在git中添加了你的origin,你就可以将你的本地提交推到远程的origin

git push -u origin --all

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教程

我也有同样的问题,但我找到了解决方案。基本上,“origin”是项目克隆位置的另一个名称。现在是错误

fatal: remote origin already exists.

字面意思是原点已经存在。因此,要解决这个问题,我们的目标应该是消除它。 为此目的:

git remote rm origin

现在再添加一次

git remote add origin https://github.com/__enter your username here__/__your repositoryname.git__

这确实解决了我的问题。