Move a git repository to another location.

Posted by peter on Wednesday, August 19, 2015

You might think that when moving a git repository from one location to another, all you have to do is to clone and then push to the new location. That is not true. You have to make sure that all remote branches and tags are included. Note that the following instructions will also push all your local branches to.

The following steps will move a repository called my_repo from Google Code to Github. Of course you can use the same steps to move from and to which ever git hosting service you like.

Step by step instructions
  1. Clone the the repository

    git clone
    cd my_repo

  2. List all local and remote branches. Note: All branches will be pushed later, both local and remote.

    git branch -a

  3. Track all remote branches.

    for remote in git branch -r | grep -v '\->'; do git branch –track ${remote#*/} $remote; done

  4. Add the new remote repository.

    git remote add new-origin

  5. List all remote repositories.

    git remote -v
  6. Push all branches to the new remote repository location.

    git push -u –all new-origin

  7. Push all tags to the new remote repository location.

    git push –tags new-origin

  8. Remove or rename the old origin

    git remote rm origin  # or rename ‘git remote rename origin old-origin’

  9. Rename the new-origin.

    git remote rename new-origin origin

  10. List all remote repositories.

    git remote -v
Thats it!

comments powered by Disqus