Jill Talamo
Jill Talamo

Reputation: 51

Git error message "remote origin already exists"

I created a repo on github, then tried to connect to it and got this error:

$ git remote add origin https://github.com/jatalamo/heroku-test-site.git fatal: remote origin already exists.

This did not happen yesterday when I created a different repo. Can anyone help me figure out how to push to this existing repo on gibash? I'm a total newbie!

Upvotes: 3

Views: 8068

Answers (3)

Agung Sudrajat
Agung Sudrajat

Reputation: 328

First: git remote remove origin

Second: git remote add origin https://(token)@github.com/username/repository-name

Last: git push

It always works for me. If not, I realized that I made mistakes.

Upvotes: 3

QandA
QandA

Reputation: 55

Open up .git/config and manually change the url of the remote repository under [remote "origin"]. Then try it again.

Upvotes: 0

PK.
PK.

Reputation: 2631

The reason you're getting remote origin already exist is because a remote by the name of origin already exists. You can check by typing git remote -v which will show you all the remotes of your git repo. You should see this:

origin  https://github.com/jatalamo/heroku-test-site.git (fetch)
origin  https://github.com/jatalamo/heroku-test-site.git (push)

The command to clone your github repo is git clone https://github.com/jatalamo/heroku-test-site.git <folder_name>. If you do that a remote called origin would be automatically setup for you, therefore you do not need to add https://github.com/jatalamo/heroku-test-site.git as a remote manually by typing git remote add origin https://github.com/jatalamo/heroku-test-site.git.

The case in which you would need to type git remote add origin https://github.com/jatalamo/heroku-test-site.git is when you are not cloning from github but instead you typed git init on your local machine and there is not remote, so you'll have to manually add the github url as a remote called origin or whatever other name you like.

You should be able to then pull and push using these commands:

git pull origin master
git push origin master

Upvotes: 2

Related Questions