Converting mercurial repositories to git
For the last little while I’ve stored meh in a mercurial repository I’ve hosted myself. Recently, I’ve wanted to move over to git and host it on github. Converting between the two turned out to be surprisingly simple using hg-git. Here’s what I did.
First I made a new empty git repository
$ mkdir meh-git $ cd meh-git $ git init Initialized empty Git repository in /home/jhawthorn/meh-git/.git/
Next I installed hg-git, a mercurial plugin which allows you to push and pull from git repositories. Once installed I ran this from the directory of my existing meh repository.
$ hg gremote add origin ../meh-git $ hg gpush
I was then able to push the new git repository to github without any trouble. You could also probably push directly to a remote github repository, skipping the intermediate local one.
I needed to slightly change the author details, to match that of my github account. Github provides an example of how to change author details in commit history. As I’m the sole author of meh, I was able to just use the following.
$ git filter-branch --env-filter ' export GIT_AUTHOR_NAME="John Hawthorn" export GIT_AUTHOR_EMAIL="firstname.lastname@example.org" export GIT_COMMITTER_NAME="John Hawthorn" export GIT_COMMITTER_EMAIL="email@example.com" '