This is basically a copy of an article from Lorenzo Mori that explains how to convert hg repositories to git repositories on Windows. I wanted to be sure having a copy. At the end there is a minor update.
Prerequisite : Install Git and TortoiseHG
First, I had to install Git (of course!) You can follow this link that has a super useful guide to do so and it’ll tell you all you need to know. Next install TortoiseHG from here: I use it as a Mercurial client but it also has a neat and useful extension which we are going to use to convert Hg to Git, called hggit.
Once everything is installed there are a few extra steps before the conversion.
Enable hggit in TortoiseHG
Open TortoiseHG workbench, go to File -> Settings and the Extension tab: select hggit.
Now that is enabled, we need to add a few extra settings to our mercurial settings file. This file is usually found in C:\Users\YOUR_USER\mercurial.ini
Add the following to the file:
hgext.bookmarks = [git] intree = True
Convert Mercurial to Git
In order to do the conversion you’ll need to open your Powershell / Command Prompt, navigate to your mercurial repository and then execute in order:
hg bookmark -r default master hg gexport --debug
This creates a git bare repository. Bare repositories are generally used for sharing purposes, so what you need is a working directory instead: that is where you will be able to do ‘commit’ and ‘push’ onto your repository. To do this, you have to set the bare flag of your repository to false and reset the repository to start fresh (still in Powershell or Command Prompt):
git config --bool core.bare false git reset HEAD -- .
Almost there! your folder structure should look like this
You can delete the .hg folder and there you have a git repository.
You can check the status of your repository to make sure everything is in place:
git status On branch master nothing to commit, working tree clean
If anything has gone wrong you can reset the repository with:
.gitignore is not created from .hgignore during above process. You will have to create .hgignore yourself starting from a copy from .gitignore. Realize though the syntax is different. This site I found a handy quick reference.