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.

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

Comments are closed.