Cloning a Mercurial repository into Git

An update to my earlier post, setting up a new dev. box and wanted to pull projects from a Mercurial repo and use them in a local Git Repo. Here’s the steps:

Install Python

1. install latest x86 (32 bit, not 64 bit) 2.7 series Python, I used version 2.7.6 from here:

2. Set an environment variable called PYTHONPATH to


3. Prepend or append this the Python path this on to the windows path


4. Install Easy_Install from:

in my casse I followed the Windows 8 PowerShell install instructions, running PowerShell as Admin and entering:

(Invoke-WebRequest | python -


Install Mercurial

5. Install the Mercurial x86 app for Windows, go to:


Install HG-GIT ..

6. install Dulwich (required by HG-GIT)

At the command prompt type:

easy_install "Dulwich>=0.8.0"

note: windows users need double quotes, not single as the hg-git site suggests. In addition, if you get an error during install: unable to find vcvarsall.bat, then add this environment variable (if Visual Studio 2012 installed)


reopen a command window and try again.

(thanks to : for the answer to this)

7. Install HG-GIT; in a command window type:

easy_install hg_git

8. Configure Mercurial, (note for Windows user it is mercurial.ini and not ~/.hgrc) so edit the file


in a text editor, add the following lines:

[ui] username = FirstName LastName <>
editor = notepad++.exe 
hgext.bookmarks = 
dulwich = C:\Python27\Lib\site-packages\dulwich-0.9.5-py2.7-win32.egg\dulwich 
hg-git = c:\python27\lib\site-packages\hg_git-0.5.0-py2.7.egg\hggit

note: you may need to update the version numbers/paths


These are the steps for cloning from a remote Mercurial repo to a local Git repo:

Cloning from a remote Mercurial repo. to a local Mercurial repo.

1. Open up a command prompt, navigate to the location you want the repository to be put in, eg.,

cd \code\mercurial

2. clone the repository, for example Jon Skeet’s Noda time:

hg clone

Cloning from a local Mercurial repo to a local Git repo:

Navigate inside the directory mercurial just created, named after the repository.  In this example it would be


(1) edit the file hgrc using a text editor

add the following 2 lines to the end of the file, save and close.

intree = true

(2) in a command window,  inside the Mercurial repo (in this example, it would be in the directory c:\code\mercurial\noda-time ) type:

hg bookmark -r default master
hg gexport 

This second command creates a .git repo beside the .hg repo, it is a private repo ready to clone from using Git. Depending on the size of the repository, this second command may take as long as a few minutes to execute.

(3) Clone from the private repo to your working / public git repo into a local directory under which you would like the Git repo to be put, following the above example it would be:

cd \development\projects
git clone c:\code\mercurial\noda-time

now you will have a working local Git repository in this directory:

cd \development\projects\noda-time