Migrate a git repository to a new host

git migration github

Recently at work I had to migrate our git repositories which we hosted our self to Github. And I wanted to share with you how I’ve done it.

First we need to do a bare clone of your old git repository. A bare clone will get all of the tags and local branches but no remote tracking branches and other refs these are completely ignored.

git clone --bare git@oldrepository:repo.git repoClone
cd repoClone

Then push the code to your new repository

git push --mirror git@github.com:username/repo.git

Remove the repository clone

rm -Rf repoClone/

Change the remote url of your repository

cd your-repo
git remote set-url origin git@github.com:username/repo.git

That’s all!

Note: Following guidelines should work with any repository hosting.

Comments

comments powered by Disqus