Github "fatal: remote origin already exists"
I am trying to follow along Michael Hartl's Rails tutorial but I've run across an error.
I signed up on Github and issued a new SSH key and made a new repository. 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?
TL;DR you should just update the existing remote:
$ 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:
$ 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". For example $ git push origin master
should now be $ git push github master
.
However, if you want to see what that origin
which already exists is, you can do a $ 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
In Short,
git remote rm origin
git remote add origin git@github.com:username/myapp.git
Worked !
Cheers!
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.
Window's POSH~Git for Windows PowerShell (and GitHub for Windows' app) has a problem with this.
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:gdcodeoctopress [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:
C:gdcodeoctopress [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.
链接地址: http://www.djcxy.com/p/27068.html上一篇: 无法移除远程原点
下一篇: Github“致命:远程起源已经存在”