远程源在'git push'上已经存在于新的存储库中

问题描述 投票:448回答:14

我在GitHub的某个地方有我的项目,[email protected]:myname/oldrep.git

现在我想将我的所有代码推送到其他位置的新存储库[email protected]:newname/newrep.git

我使用了命令:

git remote add origin [email protected]:myname/oldrep.git

但我收到了这个:

致命的:远程起源已经存在。

git github git-push git-remote
14个回答
739
投票

您收到此错误,因为“origin”不可用。 “origin”是一种惯例,不是命令的一部分。 “origin”是远程存储库的本地名称。

例如,你也可以写:

git remote add myorigin [email protected]:myname/oldrep.git  
git remote add testtest [email protected]:myname/oldrep.git

参见手册:

http://www.kernel.org/pub/software/scm/git/docs/git-remote.html

要删除远程存储库,请输入:

git remote rm origin

如果要删除“上游”远程,“origin”是远程存储库的名称:

git remote rm upstream

4
投票

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

git remote add origin [email protected]:myname/oldrep.git

git remote add neworigin [email protected]:myname/oldrep.git

我认为这应该有效。

是的,这些是针对存储库init并添加新的远程。只是换了名字。


3
投票

您还可以在REPOHOME / .git / config文件中更改要推送到的存储库名称

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


3
投票
  1. git remote rm origin
  2. git remote -v它不会显示任何存储库名称
  3. git remote add origin [email protected]:username/myapp.git
  4. git push origin master它将启动该过程并创建新分支。你可以看到你的工作被推送到github。

0
投票

当您忘记进行第一次提交时,也会发生这种情况。


0
投票

打开Android Studio> VCS> Git>遥控器删除此部分中显示的所有地址。问题将解决。

image


231
投票

以前的解决方案似乎忽略了原点,他们只建议使用其他名称。当你只想使用git push origin时,继续阅读。

出现问题的原因是遵循了错误的Git配置顺序。您可能已经在.git配置中添加了“git origin”。

您可以使用以下行更改Git配置中的远程源:

git remote set-url origin [email protected]:username/projectname.git

此命令为要推送到的Git存储库设置新URL。重要的是填写您自己的用户名和项目名称


71
投票

如果您错误地将本地名称命名为“origin”,则可以使用以下命令将其删除:

git remote rm origin

17
投票

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 [email protected]:USERNAME/REPOSITORY.git

如果尝试更新不存在的遥控器,则会收到错误。所以要小心。

METHOD3->

使用git remote rename命令重命名现有远程。现有的远程名称,例如origin。

git remote rename origin startpoint
# Change remote name from 'origin' to 'startpoint'

验证远程的新名称 - >

git remote -v

如果Git的新手试试这个教程 - >

TRY GIT TUTORIAL


15
投票

您只需在文本编辑器中编辑配置文件即可。

~/.gitconfig中你需要输入如下内容:

[user]
        name  = Uzumaki Naruto
        email = [email protected]

[github]
        user = myname
        token = ff44ff8da195fee471eed6543b53f1ff

oldrep/.git/config文件中(在存储库的配置文件中):

[remote "github"]
        url = [email protected]:myname/oldrep.git
        push  = +refs/heads/*:refs/heads/*
        push  = +refs/tags/*:refs/tags/*

如果存储库的配置文件中有远程部分,并且URL匹配,则只需添加推送配置。如果您使用公共URL进行提取,则可以将推送的URL作为'pushurl'(警告:这需要刚刚发布的Git版本1.6.4)。


8
投票

您不必删除现有的“origin”遥控器,只需使用“origin”以外的名称进行远程添加即可。

git remote add github [email protected]:myname/oldrep.git


6
投票

我遇到了同样的问题,这是我在进行一些研究后如何修复它:

  1. 下载GitHub for Windows或使用类似的东西,包括一个shell
  2. 从任务菜单中打开Git Shell。这将打开包含Git命令的电源shell。
  3. 在shell中,切换到旧存储库,例如cd C:\path\to\old\repository
  4. 显示旧存储库的状态 键入git remote -v以获取fetch和push remote的远程路径。如果您的本地存储库连接到远程,它将显示如下内容: 起源https://[email protected]/team-or-user-name/myproject.git(fetch)起源https://[email protected]/team-or-user-name/myproject.git(推) 如果它没有连接,它可能只显示origin
  5. 现在使用从本地存储库中删除远程存储库 git remote rm origin
  6. 再次检查第4步。它应该只显示origin,而不是fetch和push路径。
  7. 现在您的旧远程存储库已断开连接,您可以添加新的远程存储库。使用以下命令连接到新存储库。

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

cd /path/to/my/repo # If haven't done yet
git remote add mynewrepo https://[email protected]/team-or-user-name/myproject.git
git push -u mynewrepo master # To push changes for the first time

而已。


6
投票
git remote rm origin
git remote add origin [email protected]:username/myapp.git

5
投票

当我第一次使用Bitbucket设置时,我遇到了同样的问题。

我的问题是我需要为自定义的东西改变单词的起源。我使用了应用程序的名称。所以:

git remote add AppName https://[email protected]/somewhere/something.git
© www.soinside.com 2019 - 2024. All rights reserved.