我试图按照迈克尔哈特尔的Rails教程,但我遇到了一个错误。
我在GitHub注册了,发放了一个新的SSH密钥,并创建了一个新的存储库。但是当我在终端中输入下一行时,我得到了以下错误:
Parkers-MacBook-Pro:.ssh ppreyer$ git remote add origin git@github.com:ppreyer/first_app.git
fatal: remote origin already exists.
只是想知道是否有人遇到过这个问题?
我试图按照迈克尔哈特尔的Rails教程,但我遇到了一个错误。
我在GitHub注册了,发放了一个新的SSH密钥,并创建了一个新的存储库。但是当我在终端中输入下一行时,我得到了以下错误:
Parkers-MacBook-Pro:.ssh ppreyer$ git remote add origin git@github.com:ppreyer/first_app.git
fatal: remote origin already exists.
只是想知道是否有人遇到过这个问题?
当前回答
至少在bash上,我们可以强制命令的退出代码的返回值为0
您可以删除旧的远程并重新添加它
git remote remove $1 || true
git remote add $1 $2
其他回答
如果你得到一个类似“错误:远程源已经存在”的错误。 然后,请尝试以下命令删除已经存在的远程源
git remote remove origin
然后使用你的命令
git remote add origin git@github.com:ppreyer/first_app.git
如果您不想删除现有的远程记录,请更新它
git remote set-url <REMOTE-NAME> <NEW-URL>
然后使用你的命令
git remote add origin git@github.com:ppreyer/first_app.git
如果要重命名现有项目,请使用以下命令
git remote rename <old-name> <new-name>
如果要将原始远程重命名为backup。你只需运行:
git remote rename origin backup
谢谢你! !
对于那些遇到非常常见的错误“fatal: remote origin already exists.”,或者当试图删除origin时得到“error: could not remove config section remote.”原点”,你需要做的就是手动设置原点。
Windows的POSH~Git for Windows PowerShell(和GitHub for Windows的应用程序)在这方面有一个问题。
就像我经常遇到的那样,我又一次在布置我的章鱼女时遇到了这种情况。这就是我如何让它工作的。
首先,检查你的遥控器:
C:\gd\code\octopress [source +2 ~3 -0 !]> git remote -v
octopress https://github.com/imathis/octopress.git (fetch)
octopress https://github.com/imathis/octopress.git (push)
origin
您首先会注意到我的原点没有url。任何删除它、重命名它的尝试都失败了。
因此,手动更改url:
git remote set-url --add origin https://github.com/eduncan911/eduncan911.github.io.git
然后你可以再次运行git remote -v来确认它是有效的:
C:\gd\code\octopress [source +2 ~3 -0 !]> git remote -v
octopress https://github.com/imathis/octopress.git (fetch)
octopress https://github.com/imathis/octopress.git (push)
origin https://github.com/eduncan911/eduncan911.github.io.git (fetch)
origin https://github.com/eduncan911/eduncan911.github.io.git (push)
这已经修复了数十个我遇到的问题,GitHub, BitBucket GitLab等。
为了使用git,你必须
根
如果没有,那就用sudo
去除原点: Git远程删除原点
添加原点:
Git远程添加origin http://giturl
该错误消息表明您的git目录中已经有一个远程服务器。 如果您对那个遥控器感到满意,您就可以推送您的代码。如果没有或者你不能推,就:
git remote remove origin
git remote add origin git@github.com:ppreyer/first_app.git
瞧!
在Windows上使用git bash将存储库添加到git hun时遇到同样的错误
git remote add origin https://github.com/axaysushir/netflix_page_clone.git
致命:远程源已经存在。
fatal: remote origin already exists.
! [rejected] master -> master (fetch first)
错误:无法将一些引用推到“https://github.com/axaysushir/meditation_app_using_js.git”
通过以下命令更新存储库
$ git remote set-url origin https://github.com/axaysushir/netflix_page_clone.git
然后添加存储库使用git远程添加github而不是git远程添加起源
$ git remote add github https://github.com/axaysushir/netflix_page_clone.git
然后写以下命令,而不是git push origin master,这将把你的存储库上传到github
$ git push github master