Join the Stack Overflow Community
Stack Overflow is a community of 6.3 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I have my project on GitHub at some location, git@github.com:myname/oldrep.git.

Now I want to push all my code to a new repository at some other location, git@github.com:newname/newrep.git.

I used the command:

git remote add origin git@github.com:myname/oldrep.git

but I am receiving this:

fatal: remote origin already exists.

share|improve this question
4  
Give the output of the command $> git remote -v show – sykora Aug 3 '09 at 11:50
    
possible duplicate of Github "fatal: remote origin already exists" – That Brazilian Guy Feb 5 '14 at 14:52
    
A good way is to use "import from another repository" at the bottom of your new created repository, if you know the URL of the old one. – JW.ZG Jul 16 at 4:58
    
A similar question was asked here: stackoverflow.com/questions/2432764/… – jciloa Sep 27 at 12:46
up vote 450 down vote accepted

You are getting this error because "origin" is not available. "origin" is a convention not part of the command. "origin" is the local name of the remote repository.

For example you could also write:

git remote add myorigin git@github.com:myname/oldrep.git  
git remote add testtest git@github.com:myname/oldrep.git

See the manual:

http://www.kernel.org/pub/software/scm/git/docs/git-remote.html

To remove a remote repository you enter:

git remote rm origin

Again "origin" is the name of the remote repository if you want to remove the "experimental" branch on the remote.

git remote rm experimental
share|improve this answer
4  
"git remote rm origin" didn't work from me, if it doesn't work for you try to check with "git remote -v" this will show you if your origin has a url set, if it doesn't likely you did the init locally and are trying to push it remote, and made a misstep like me). Then follow RobinH's answer: git remote set-url origin git@github.com:username/projectname.git – Clarence Liu May 23 '14 at 1:46
1  
check this answer in order to force the url. – srodriguex Jun 5 '14 at 21:32
    
"git remote rm origin" worked like a charm, wonderful! :) puhh, I'm new to the terminology of git so it was a bigger search, but your answer helped me a lot. :) thank you! – Martin Pfeffer Dec 9 '14 at 23:25
    
git push -u origin master --force – Ron Royston Aug 3 at 20:50

The previous solutions seem to ignore origin, and they only suggest to use another name. When you just want to use git push origin, keep reading.

The problem appears because a wrong order of Git configuration is followed. You might have already added a 'git origin' to your .git configuration.

You can change the remote origin in your Git configuration with the following line:

git remote set-url origin git@github.com:username/projectname.git

This command sets a new URL for the Git repository you want to push to. Important is to fill in your own username and projectname

share|improve this answer
7  
Thanks, exactly what I had to do :) – winkbrace Mar 27 '13 at 19:19
5  
This is the answer! – zdd Mar 18 '14 at 12:30
    
This fiexd it for me. But what really help me with this problem was because I user portableGit that was installed with Gihub for windows. I found the solution here – PerseP Mar 18 '14 at 19:57
1  
Just what i needed – bjornhol Aug 14 '14 at 19:08
2  
This is the best answer IMHO – kratos Jul 1 at 14:34

If you have mistakenly named the local name as "origin", you may remove it with the following:

git remote rm origin
share|improve this answer
    
What does" mistakenly named the local name as 'origin'" actually mean?Can you explain it in detail?@Ozgur – Yuan Wen Jul 18 at 5:43

You can simply edit your configuration file in a text editor.

In the ~/.gitconfig you need to put in something like the following:

[user]
        name  = Uzumaki Naruto
        email = myname@example.com

[github]
        user = myname
        token = ff44ff8da195fee471eed6543b53f1ff

In the oldrep/.git/config file (in the configuration file of your repository):

[remote "github"]
        url = git@github.com:myname/oldrep.git
        push  = +refs/heads/*:refs/heads/*
        push  = +refs/tags/*:refs/tags/*

If there is a remote section in your repository's configuration file, and the URL matches, you need only to add push configuration. If you use a public URL for fetching, you can put in the URL for pushing as 'pushurl' (warning: this requires the just-released Git version 1.6.4).

share|improve this answer

You don't have to remove your existing "origin" remote, just use a name other than "origin" for your remote add, e.g.

git remote add github git@github.com:myname/oldrep.git

share|improve this answer

I got the same issue, and here is how I fixed it after doing some research:

  1. Download GitHub for Windows or use something similar, which includes a shell
  2. Open the Git Shell from task menu. This will open a power shell including Git commands.
  3. In the shell, switch to your old repository, e.g. cd C:\path\to\old\repository
  4. Show status of the old repository

  5. Now remove the remote repository from local repository by using

    git remote rm origin
    
  6. Check again with step 4. It should show origin only, instead of the fetch and push path.

  7. Now that your old remote repository is disconnected, you can add the new remote repository. Use the following to connect to your new repository.

Note: In case you are using Bitbucket, you would create a project on Bitbucket first. After creation, Bitbucket will display all required Git commands to push your repository to remote, which look similar to the next code snippet. However, this works for other repositories, too.

cd /path/to/my/repo # If haven't done yet
git remote add mynewrepo https://user@bitbucket.org/team-or-user-name/myproject.git
git push -u mynewrepo master # To push changes for the first time

That's it.

share|improve this answer

You could also change the repository name you wish to push to in the REPOHOME/.git/config file

(where REPOHOME is the path to your local clone of the repository).

share|improve this answer

I had the same problem when I first set up using Bitbucket.

My problem was that I needed to change the word origin for something self-defined. I used the name of the application. So:

git remote add AppName https://someone@bitbucket.org/somewhere/something.git
share|improve this answer

You should change the name of the remote repository to something else.

git remote add origin git@github.com:myname/oldrep.git

to

git remote add neworigin git@github.com:myname/oldrep.git

I think this should work.

Yes, these are for repository init and adding a new remote. Just with a change of name.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.