Moving git repository

Every now and then, I need to move a git repository from one host to another. And since I don’t do that very often, I always forget the sequence of commands!

This stackoverflow post outlines the process:

In words:

  1. create the new empty repository (say, on github)
  2. make a bare clone of the repository in some temporary location
  3. change to the temporary location
  4. perform a mirror-push to the new repository
  5. change to another location and delete the temporary location

In commands:

$ cd $HOME
$ git clone --bare https://oldhost/the/path/to/my_repo.git
$ cd my_repo.git
$ git push --mirror https://newhost/my_username/my_repo.git
$ cd ..
$ rm -rf my_repo.git