Github “fatal: remote origin already exists”

2019-01-03 04:05发布

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?

15条回答
劫难
2楼-- · 2019-01-03 04:05

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:

git remote rename [current name] [new name]

as in:

git remote rename origin oldrepo

You should then be able to resume your tutorial.

查看更多
迷人小祖宗
3楼-- · 2019-01-03 04:16

If you need to check which remote repos you have connected with your local repos, theres a cmd:

git remote -v

Now if you want to remove the remote repo (say, origin) then what you can do is:

git remote rm origin
查看更多
Evening l夕情丶
4楼-- · 2019-01-03 04:18

In the special case that you are creating a new repository starting from an old repository that you used as template (Don't do this if this is not your case). Completely erase the git files of the old repository so you can start a new one:

rm -rf .git

And then restart a new git repository as usual:

git init
git add whatever.wvr ("git add --all" if you want to add all files)
git commit -m "first commit"
git remote add origin git@github.com:ppreyer/first_app.git
git push -u origin master
查看更多
Explosion°爆炸
5楼-- · 2019-01-03 04:19

for using git you have to be

root

if not then use sudo

for removing origin :

git remote remove origin

for adding origin :

git remote add origin http://giturl

查看更多
干净又极端
6楼-- · 2019-01-03 04:20

Try this

  • cd existing_repo
  • git remote rename origin old-origin
查看更多
一夜七次
7楼-- · 2019-01-03 04:22

That error message indicates that you already have a remote in your git directory. If you are satisfied with that remote, your can push your code. If not or if you can't push just:

git remote remove origin
git remote add origin git@github.com:ppreyer/first_app.git

Voilà !

查看更多
登录 后发表回答