我在GitHub的某个地方有我的项目,[email protected]:myname/oldrep.git
。
现在我想将我的所有代码推送到其他位置的新存储库[email protected]:newname/newrep.git
。
我使用了命令:
git remote add origin [email protected]:myname/oldrep.git
但我收到了这个:
致命的:远程起源已经存在。
您收到此错误,因为“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
您应该将远程存储库的名称更改为其他名称。
git remote add origin [email protected]:myname/oldrep.git
至
git remote add neworigin [email protected]:myname/oldrep.git
我认为这应该有效。
是的,这些是针对存储库init并添加新的远程。只是换了名字。
您还可以在REPOHOME / .git / config文件中更改要推送到的存储库名称
(其中REPOHOME是存储库的本地克隆的路径)。
git remote rm origin
git remote -v
它不会显示任何存储库名称git remote add origin [email protected]:username/myapp.git
git push origin master
它将启动该过程并创建新分支。你可以看到你的工作被推送到github。当您忘记进行第一次提交时,也会发生这种情况。
打开Android Studio> VCS> Git>遥控器删除此部分中显示的所有地址。问题将解决。
以前的解决方案似乎忽略了原点,他们只建议使用其他名称。当你只想使用git push origin
时,继续阅读。
出现问题的原因是遵循了错误的Git配置顺序。您可能已经在.git配置中添加了“git origin”。
您可以使用以下行更改Git配置中的远程源:
git remote set-url origin [email protected]:username/projectname.git
此命令为要推送到的Git存储库设置新URL。重要的是填写您自己的用户名和项目名称
如果您错误地将本地名称命名为“origin”,则可以使用以下命令将其删除:
git remote rm origin
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的新手试试这个教程 - >
您只需在文本编辑器中编辑配置文件即可。
在~/.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)。
您不必删除现有的“origin”遥控器,只需使用“origin”以外的名称进行远程添加即可。
git remote add github [email protected]:myname/oldrep.git
我遇到了同样的问题,这是我在进行一些研究后如何修复它:
Git Shell
。这将打开包含Git命令的电源shell。cd C:\path\to\old\repository
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
。git remote rm origin
origin
,而不是fetch和push路径。注意:如果您使用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
而已。
git remote rm origin
git remote add origin [email protected]:username/myapp.git
当我第一次使用Bitbucket设置时,我遇到了同样的问题。
我的问题是我需要为自定义的东西改变单词的起源。我使用了应用程序的名称。所以:
git remote add AppName https://[email protected]/somewhere/something.git