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:
- create the new empty repository (say, on github)
- make a bare clone of the repository in some temporary location
- change to the temporary location
- perform a mirror-push to the new repository
- change to another location and delete the temporary location
$ 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