Dariusz on Software Quality & Performance


Change "origin" of your GIT repository

Filed under: en — Tags: , — dariusz.cieslak @

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
origin zeus.aplikacja.info:cust-proj1

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

$ git remote rm origin
$ git remote add origin git@github.com:aplikacjainfo/proj1.git
$ 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.


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

    Comment by Greg — 02/09/2011 @

  2. 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.

    Comment by dariusz.cieslak — 06/09/2011 @

  3. [...] Switch “Origin” of Your Git Repository. Cieslak, Dariusz. Aplikacja.info. 10 Aug. 2010. This entry was posted in regular and tagged centos, git, rhel, ssh. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL. « Install WordPress on CentOS/RHEL in Five Minutes Flat (remix) A Low-Impact Woodland Home » [...]

    Pingback by How to Move a Github Repository to Your Private RHEL or CentOS Server — 22/10/2011 @

  4. Do your steps accomplish the same thing as changing the remote's URL? In http://help.github.com/remotes/, they give the following example under the title "Changing a remote's URL":

    git remote set-url example git://github.com/user/test.git

    will set the URL of the remote named “example” to git://github.com/user/test.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?


    Comment by Erica — 06/01/2012 @

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

    Comment by dariusz.cieslak — 06/01/2012 @

  6. I think it's relatively new.

    Comment by Erica — 06/01/2012 @

  7. [...] to: http://blog.aplikacja.info/2010/08/switch-origin-of-your-git-repository/ Share this:TwitterFacebookLinkedInLike this:LikeBe the first to like this. [...]

    Pingback by Moving Git Repos « inthecloud247 — 14/11/2012 @

  8. [...] Thanks to: http://blog.aplikacja.info/2010/08/switch-origin-of-your-git-repository/ [...]

    Pingback by Moving Git Repos « inthecloud247 — 14/11/2012 @

  9. 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.

    Comment by Peter — 09/02/2013 @

  10. Worked first time! Thanks for sharing.

    Comment by Philip — 11/03/2013 @

  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.

    Comment by Jeremy Ehrhardt — 07/04/2013 @

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

    Comment by Walter — 27/06/2013 @

  13. 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.

    Comment by Irving A. Bermúdez S. — 11/07/2013 @

  14. That worked perfectly

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


    Comment by Mariano — 06/09/2013 @

  15. [...] bit easy, though I read through the first 5 or so google search results before I did anything. This blog post was the most helpful because the commands were explained very nicely. It probably also [...]

    Pingback by Github repo confusion | Clare Codes — 17/09/2013 @

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress