Converting Mercurial Repos To Git

I have tried many different ways of converting Mercurial (Hg) repositories to Git repositories. Some of them didn’t work, some of them worked, and some of them, well, worked better.

Here is my favourite method, assuming you are using Linux (I was running Ubuntu). If you are not running Linux, I seriously recommend running it on a virtual machine just because it is easier to manipulate repositories that way.

Firstly, download the hggit plugin for Mercurial. Don’t get this confused with the githg plugin (which has similar, but different, functionality).

Now, you have to add a few lines to your global Mercurial config file (~./.hgrc) so that Mercurial will load the hggit plugin next time you use it.

Now, navigate to the root directory of your Mercurial repo that you wish to convert, and run the following command, which adds a “Master” branch to the repo, so that it is Git-compatible.

Now, all you have to do is push to your empty Git repository, using the standard Mercurial push command! The hggit plugin automatically converts it for you as part of the push command. For example, if you were pushing to a newly created repository on GitHub,

You don’t have push to GitHub, you can push to any Git repo, including those on BitBucket, or one you have created on you computer (using the command $ git init in an empty directory).

Note that you must have set up SSH keys on GitHub for this to work correctly. If you haven’t, go here and find out how.

Posted: May 20th, 2013 at 8:33 pm
Last Updated on: December 19th, 2016 at 10:57 pm

Leave a Reply