Github“致命:远程起源已经存在”

在尝试按照Rails教程操作GitHub时遇到了'致命:远程起源已经存在'的错误。解决方案包括更新或重命名已存在的远程仓库,或手动设置远程URL。在Windows PowerShell中,可能需要直接修改配置文件来解决此问题。
摘要由CSDN通过智能技术生成

本文翻译自:Github “fatal: remote origin already exists”

I am trying to follow along Michael Hartl's Rails tutorial but I've run across an error. 我想跟随Michael Hartl的Rails教程,但我遇到了一个错误。

I signed up on Github and issued a new SSH key and made a new repository. 我在Github上注册并发布了一个新的SSH密钥并创建了一个新的存储库。 But when I enter the next line into the terminal I get the following error: 但是当我进入终端的下一行时,我收到以下错误:

Parkers-MacBook-Pro:.ssh ppreyer$ git remote add origin git@github.com:ppreyer/first_app.git
fatal: remote origin already exists.

Just wondered if anybody else has run across this problem? 只是想知道是否有其他人遇到过这个问题?


#1楼

参考:https://stackoom.com/question/jkiR/Github-致命-远程起源已经存在


#2楼

TL;DR you should just update the existing remote: TL; DR你应该只更新现有的遥控器:

$ git remote set-url origin git@github.com:ppreyer/first_app.git

Long version: 长版:

As the error message indicates, there is already a remote configured with the same name. 如错误消息所示,已经配置了具有相同名称的远程。 So you can either add the new remote with a different name or update the existing one if you don't need it: 因此,您可以使用其他名称添加新远程,或者在不需要时更新现有远程:

To add a new remote, called for example github instead of origin (which obviously already exists in your system), do the following: 要添加一个新的远程,例如github而不是origin (显然已经存在于您的系统中),请执行以下操作:

$ git remote add github git@github.com:ppreyer/first_app.git

Remember though, everywhere in the tutorial you see "origin" you should replace it with "github" . 但请记住,在教程的任何地方,您都会看到“origin”,您应该将其替换为“github” For example $ git push origin master should now be $ git push github master . 例如$ git push origin master现在应该是$ git push github master

However, if you want to see what that origin which already exists is, you can do a $ git remote -v . 但是,如果你想看看已存在的origin是什么,你可以做一个$ git remote -v If you think this is there by some error, you can update it like so: 如果您认为这是由于某些错误,您可以像这样更新它:

$ git remote set-url origin git@github.com:ppreyer/first_app.git

#3楼

You can see what remote repositories you are configured to connect to via 您可以查看配置为通过哪些远程存储库连接

git remote -v

That will return a list in this format: 这将以这种格式返回一个列表:

origin  git@github.com:github/git-reference.git (fetch)
origin  git@github.com:github/git-reference.git (push)

That might help you figure out what the original 'origin' pointed to. 这可能会帮助你弄清楚原始的“起源”指向的是什么。

If you want to keep the remote connection that you see with the -v, but still want to follow the Rails tutorial without having to remember 'github' (or some other name) for your tutorial's repo, you can rename your other repository with the command: 如果你想保留你用-v看到的远程连接,但是仍然想要遵循Rails教程而不必记住教程的repo的'github'(或其他名称),你可以用你的命令重命名你的其他存储库命令:

git remote rename [current name] [new name]

as in: 如:

git remote rename origin oldrepo

You should then be able to resume your tutorial. 然后,您应该能够恢复教程。


#4楼

For those of you running into the ever so common error "fatal: remote origin already exists.", or when trying to remove origin and you get "error: could not remove config section remote.origin", what you need to do is to set the origin manually. 对于那些遇到如此常见的错误“致命:远程来源已经存在。”,或者当试图删除原点而你得到“错误:无法删除配置部分remote.origin”时,你需要做的是手动设置原点。

Window's POSH~Git for Windows PowerShell (and GitHub for Windows' app) has a problem with this. Window的POSH~Git for Windows PowerShell(和GitHub for Windows'app)有一个问题。

I ran into this, like I do so often, again when setting up my octopress. 在设置我的章鱼时,我经常遇到这种情况,就像我经常这样做。 So, here's how I got it working. 所以,这就是我如何运作。

First, check your remotes: 首先,检查你的遥控器:

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

You'll first note that my origin has no url. 你会首先注意到我的起源没有网址。 Any attempt to remove it, rename it, etc all fails. 任何删除它,重命名等的尝试都会失败。

So, change the url manually: 所以,手动更改网址:

git remote set-url --add origin https://github.com/eduncan911/eduncan911.github.io.git

Then you can confirm it worked by running git remote -v again: 然后你可以通过再次运行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)

This has fixed dozens of git repos I've had issues with, GitHub, BitBucket GitLab, etc. 这已经修复了我遇到的几十个git repos,GitHub,BitBucket GitLab等。


#5楼

In Short, 简而言之,

git remote rm origin
git remote add origin git@github.com:username/myapp.git

Worked ! 工作了!

Cheers! 干杯!


#6楼

First do a: 先做一个:

git remote rm origin

then 然后

git remote add origin https://github.com/your_user/your_app.git

and voila! 瞧! Worked for me! 为我工作!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值