我有我的项目在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”是一个约定,不是命令的一部分。“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

我也遇到过同样的问题,在做了一些研究之后,我是这样解决的:

下载GitHub for Windows,或使用类似的东西,其中包括一个shell。 从任务菜单中打开Git Shell。这将打开一个包含Git命令的power shell。 在shell中,切换到旧的存储库,例如cd C:\path\到\old\存储库。 显示旧存储库的状态。

输入git remote -v获取获取和推送remote的远程路径。如果您的本地存储库连接到远程存储库,它将显示如下内容: 来源https://user@bitbucket.org/team-or-user-name/myproject.git(获取) 来源https://user@bitbucket.org/team-or-user-name/myproject.git(推送) 如果没有连接,可能只显示原点。

现在通过使用从本地存储库删除远程存储库 Git远程rm来源 使用git remote -v再次检查,如步骤4所示。它应该只显示原点,而不是读取和推送路径。 现在旧的远程存储库已经断开连接,可以添加新的远程存储库了。使用以下命令连接到新的存储库:

注意:如果你正在使用Bitbucket,你会先在Bitbucket上创建一个项目。创建后,Bitbucket将显示将存储库推送到远程所需的所有Git命令,这看起来类似于下一个代码片段。但是,这也适用于其他存储库。

cd /path/to/my/repo # If you haven't done that yet.
git remote add mynewrepo https://user@bitbucket.org/team-or-user-name/myproject.git
git push -u mynewrepo master # To push changes for the first time.

就是这样。

步骤:1

git remote rm origin

一步:2

git remote add origin enter_your_repository_url

例子:

git remote add origin https://github.com/my_username/repository_name.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 remote rm origin
git remote add origin git@github.com:username/myapp.git