How to remove remote origin from a Git repository

1,000,230

Solution 1

Instead of removing and re-adding, you can do this:

git remote set-url origin git://new.url.here

See this question: How to change the URI (URL) for a remote Git repository?

To remove remote use this:

git remote remove origin

Solution 2

If you insist on deleting it:

git remote remove origin

Or if you have Git version 1.7.10 or older

git remote rm origin

But kahowell's answer is better.

Solution 3

To remove a remote:

git remote remove origin

To add a remote:

git remote add origin yourRemoteUrl

and finally

git push -u origin master

Solution 4

you can try this out,if you want to remove origin and then add it:

git remote remove origin

then:

git remote add origin http://your_url_here

Solution 5

I don't have enough reputation to comment answer of @user1615903, so add this as answer: "git remote remove" does not exist, should use "rm" instead of "remove". So the correct way is:

git remote rm origin
Share:
1,000,230
Om3ga
Author by

Om3ga

Updated on July 08, 2022

Comments

  • Om3ga
    Om3ga 6 months

    I just did git init to initialize my folder as Git repository and then added a remote repository using git remote add origin URL. Now I want to remove this git remote add origin and add a new repository git remote add origin new-URL. How can I do it?

  • 1615903
    1615903 almost 9 years
    remove was added in 1.7.12. I have updated my answer.
  • baash05
    baash05 over 8 years
    This is the actual answer to the question "how to remove remote origin from git repo".
  • kahowell
    kahowell about 8 years
    @acannon828, the protocol necessary depends on how you're connecting to git. The example provided assumes you are using the git protocol. The git book explains various protocols supported by git.
  • Ian Lewis
    Ian Lewis about 8 years
    This is the correct answer, there is some confusion caused by the phrasing of the title and the question itself.
  • Recomer
    Recomer almost 7 years
    If you use Bitbucket instead of github you will delete the first "git://" part and directly write [email protected]:yourusername/reponame.git and of course change the place holders : "yourusername" and "reponame" with yours.
  • Michael
    Michael about 5 years
    What if I have multiple URLs associated with origin, but only want to remove one of them?
  • 1615903
    1615903 about 5 years
    @Michael what exactly do you mean by "multiple URLs associated with origin"? How is the remote configured?
  • Samuel Aiala Ferreira
    Samuel Aiala Ferreira about 4 years
    worked like a charm for me. It's not the prettiest way of doing it, but the git remote rm was not working ... and the suggestion at the github page didn't work either. Thanks
  • RobMac
    RobMac over 3 years
    but then you loose all the history, right? in that case, why not pull in the code from the other/new repository?
  • Amrit Shrestha
    Amrit Shrestha almost 3 years
    yes, it does remove the whole history. @Yasin should add some kind of warning with the answer.
  • Marko
    Marko over 1 year
    Yeah, good solution if you want to also get rid of remote history, otherwise stick to other answers :)
  • Linguistics
    Linguistics 12 months
    This is not the correct answer, the correct answer is: git remote set-url origin new.url.here. Having git:// will just cause a fatal error. Not sure why this was in the answer.
  • serup
    serup 11 months
    I do not recommend doing this, if you want to maintain the commit history
  • Ekanem Eno
    Ekanem Eno 11 months
    @Michael You can achieve that using git remote remove <name> where name is the repo name, not the full URL
  • Timo
    Timo 10 months
    rm in git remote rm works in every git version I think, not just in old ones <2.
  • cristiandatum
    cristiandatum 8 months
    just make sure to keep checking your current remote repository address using "git remote -v" otherwise you might end up removing the wrong remote repository.