[github] 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 [email protected]:ppreyer/first_app.git
fatal: remote origin already exists.

Just wondered if anybody else has run across this problem?

This question is related to github terminal github-for-mac

The answer is


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:\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:

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.


In case you want to do via GUI do the following:

  1. Ensure "hidden files" are visible in your project folder
  2. Go to .git directory
  3. Edit the url file in the config.txt file and save the file!

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  [email protected]:github/git-reference.git (fetch)
origin  [email protected]: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.


if you already add project for another storage, like you upload to github and then you upload to bitbucket then it shows this type of Error.

How to remove Error: delete git-hub file in your project and then repeat the following steps...

git init       
git remote add origin [email protected]:Yourname/firstdemotry.git  
git add -A  
git commit -m 'Message'  
git push -u origin master  

  • $ git remote add origin [email protected]:abc/backend/abc.git

    In this command origin is not part of command it is just name of your remote repository. You can use any name you want.

    • First You can check that what it contains using below command

    $ git remote -v

    It will gives you result like this origin [email protected]:abc/backend/abc.git (fetch) origin [email protected]:abc/backend/abc.git (push) origin1 [email protected]:abc/backend/abc.git (fetch) origin1 [email protected]:abc/backend/abc.git (push)

    if it contains your remote repository path then you can directly push to that without adding origin again

    • If it is not contaning your remote repository path

    Then you can add new origin with different name and use that to push like $ git remote add origin101 [email protected]:abc/backend/abc.git

    Or you can rename existing origin name add your origin

    git remote rename origin destination

    fire below command again

    $ git remote -v

    destination [email protected]:abc/backend/abc.git (fetch) destination [email protected]:abc/backend/abc.git (push)

    It will change your existing repos name so you can use that origin name

    Or you can just remove your existing origin and add your origin

    git remote rm destination


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!


It can also happen if you run the command in directory without git initialized. If that's the case run first:

git init

update the origin if it exist already using this command

git remote set-url origin https://github.com/SriramUmapathy/ReduxLearning.git

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


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

facing same error while add repository to git hun using git bash on windows

 git remote add origin https://github.com/axaysushir/netflix_page_clone.git

fatal: remote origin already exists.

fatal: remote origin already exists.

 ! [rejected]        master -> master (fetch first)

error: failed to push some refs to 'https://github.com/axaysushir/meditation_app_using_js.git'

Update repository by following command

$ git remote set-url origin https://github.com/axaysushir/netflix_page_clone.git

then add repository using git remote add github instead git remote add origin

$ git remote add github https://github.com/axaysushir/netflix_page_clone.git

And then write following command instead of git push origin master this will upload your repository to github

$ git push github master

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 [email protected]:ppreyer/first_app.git
git push -u origin master

On bash at least, we can force the return value of the exit code of the command to be 0

You can remove the old remote and add it again

git remote remove $1 || true
git remote add $1 $2

In Short,

git remote rm origin
git remote add origin [email protected]:username/myapp.git

Worked !

Cheers!


The concept of remote is simply the URL of your remote repository.

The origin is an alias pointing to that URL. So instead of writing the whole URL every single time we want to push something to our repository, we just use this alias and run:

git push -u origin master

Telling to git to push our code from our local master branch to the remote origin repository.

Whenever we clone a repository, git creates this alias for us by default. Also whenever we create a new repository, we just create it our self.

Whatever the case it is, we can always change this name to anything we like, running this:

git remote rename [current-name] [new-name]

Since it is stored on the client side of the git application (on our machine) changing it will not affect anything in our development process, neither at our remote repository. Remember, it is only a name pointing to an address.

The only thing that changes here by renaming the alias, is that we have to declare this new name every time we push something to our repository.

git push -u my-remote-alias master

Obviously a single name can not point to two different addresses. That's why you get this error message. There is already an alias named origin at your local machine. To see how many aliases you have and what are they, you can initiate this command:

git remote -v

This will show you all the aliases you have plus the corresponding URLs.

You can remove them as well if you like running this:

git remote rm my-remote-alias

So in brief:

  • find out what do you have already,
  • remove or rename them,
  • add your new aliases.

Happy coding.


Try this

  • cd existing_repo
  • git remote rename origin old-origin

First check To see how many aliases you have and what are they, you can initiate this command git remote -v

Then see in which repository you are in then try git remote set-url --add [Then your repositpory link] git push -u origin master


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 [email protected]:ppreyer/first_app.git

VoilĂ  !