Convert a Mercurial Repository to Git

An easy way to convert an existing hg reposiroty to git (on Linux).
created by on 2013-02-15


Mercurial is a great source control system with good tooling and cross-platform support, but it’s kind of slow when repositories get bigger. At least this is my experience with large repositories, Mercurial and Bitbucket.

Example of Mercurial being slow for large Repositories

The cloning of the “PowerShell-Workshop” repository from Bitbucket which contains quite of lot of screenshots and other binary data took more than 30 minutes - even though the repo has only a size of about 50 MB:


  1. Install and configure git
  2. Install and configure mercurial
  3. A mercurial repository that you want to convert to a git repository

Steps to convert a repository

You basically only need to follow the steps described in the README of the fast-export project at

Get fast-export from Github

fast-export or hg-fast-export is a shell/python script which used git-fast-import to convert mercurial repositories to git.

git clone git://

Screenshot of the cloning of fast-export from github

Screenshot of the files and scripts included in hg-fast-export project

Clone the Mercurial Repository you want to convert

This might take a while if the repository is big. This is one reason why you might want to switch from Mercurial to Git.

hg clone

Screenshot of the cloning process of a mercurial repo at bitbucket

Create a new git repository

This will be the target for your export from mercurial.

cd ~/dev/git
mkdir PowerShell-Workshop
cd PowerShell-Workshop
git init

Execute in your new git repository

cd ~/dev/git/PowerShell-Workshop
~/git/fast-export/ -r ~/dev/hg/powershell-workshop

For some strange reason deleted all files in the new repository after it converted everything successfully.
To fix this you can just unstage the changes and everything should be fine:

git reset HEAD^
git checkout .
git status
git log

After the repo has been converted

All that is left to do is change your .hgignore files to .gitignore files.


Fork allmark on GitHub