Change "origin" of your GIT repository

GIT is a distributed version control system – that means it doesn't require to have any central repository. It's possible to build system by exchanging commits between equal nodes. It's convenient, however, to mark one repository as the central one. Of course you can change your decision at any time. I'll show you how to do that.

If you created your repo copy by "clone" operation you will have "origin" remote branch defined. This remote can be used to pull/push changes.

$ git remote -v

If you decide to change this definition later you can issue the following commands:

$ git remote rm origin
$ git remote add origin
$ git config master.remote origin
$ git config master.merge refs/heads/master

After this change you can push your commits to new repository location (origin is selected as default remote branch for master, it's configured in .git/config):

$ git push

That's all. Much simpler than moving Subversion repository.

UPDATE 2011-12-09: replaced sed command with much simpler "git config" replacement.

This entry was posted in en and tagged , . Bookmark the permalink.

19 Responses to Change "origin" of your GIT repository

  1. Greg says:

    What is the sed command doing? I can't quite read it.

  2. dariusz.cieslak says:

    Looks like there's much simpler version of above sed commands:

    git config master.remote origin
    git config master.merge refs/heads/master

    sed edit-in-place does the same job.

  3. Pingback: How to Move a Github Repository to Your Private RHEL or CentOS Server

  4. Erica says:

    Do your steps accomplish the same thing as changing the remote's URL? In, they give the following example under the title "Changing a remote's URL":

    git remote set-url example git://

    will set the URL of the remote named “example” to git:// We were using the personal git account of an employee to hold our repositories, but that employee has left. I forked the repositories, and now need to change our local repositories to pull and push from the forked versions. Should I be using the "remote set-url" command, or going through the steps that you describe?


  5. dariusz.cieslak says:

    Looks like your method is MUCH simpler than mine. It does the same job (changes URL of a remote location).
    Thanks for this feedback!

  6. Erica says:

    I think it's relatively new.

  7. Pingback: Moving Git Repos « inthecloud247

  8. Pingback: Moving Git Repos « inthecloud247

  9. Peter says:

    Having tried it without success and then found instructions elsewhere, I think that the two config lines should be branch.master.remote and branch.master.merge rather than just master.remote and master.merge.

  10. Philip says:

    Worked first time! Thanks for sharing.

  11. Thanks! This is just what I needed to switch the origin of my Homebrew install to my own fork without having to wipe the Homebrew folder and install again.

  12. Walter says:

    Thanks, I was able to switch the origin and push changes to my own fork & branch without losing any changes.

  13. Irving A. Bermúdez S. says:

    Thanks for this post, it's very useful information. The only thing I have to modify for your recipe was the "git push" command:

    git push -u origin master

    That did the job entirely.

  14. Mariano says:

    That worked perfectly

    Might want to mention you will need to fetch when you have finished changing origin master.


  15. Pingback: Github repo confusion | Clare Codes

  16. Hex says:

    Or you can just do:

    git remote set-url origin git://

  17. sarath says:

    Awesome. Great job, 1+

  18. Jörg Rade says:

    Worked for me after some fiddling with the proxy, helped out here.

  19. Anonymous says:


Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>