Using Hg-Git to convert VCS with TortoiseHG and TortoiseGIT

Convert from Mercurial to GIT VCS with Hg-Git, TortoiseHG and TortoiseGIT

Discusses converting a Mercurial project to a GIT project using the Hg-Git plugin, TortoiseHG and TortoiseGIT.

Author: Kaleb Kircher

Version: 1.0

Refactoring History

v1.0 Authored

Copy write: 2012, 2013, 2014 Kircher Engineering, LLC

The Situation:

I wanted to convert some of my Mercurial projects hosted on BitBucket over to Git projects so I could host them on GitHub. I use TortoiseHG and TortoiseGit to help me manage the VCS's on a Windows machine and these are the steps I took to successfully convert the projects.

Install Hg-Git Plugin:

Hg-Git is a plugin for Mercurial, adding the ability to push to and pull from a Git server repository from Mercurial. We will be using ToroiseGit on Windows and the documentation states that the TortoiseHg Windows installers come with the python-git bindings (named dulwich) that hg-git requires, so one only needs to clone the hg-git repository to your local computer.

Since we want the clone method, we can clone the repository on our machine:

hg clone C:\hg-git

Then enable hggit and bookmarks in your Mercurial.ini file. To do this, we can open TortoiseHG, click File -> Settings and then clicking the 'Edit File' button.

Then we can add the following lines to the file:

bookmarks =
hggit = C:\hg-git\hggit

Converting from Mercurial to Git:

1.) Now that TortoiseHG is configured to use the Hg-Git Plugin, we can begin to convert the project from Mercurial to Git. First, we need a new, temporary folder. Once you have created the new folder, right click on the folder and select the TortoiseGit option Git Create repository here option. Make sure you select the Make It Bear option. Click Ok.

2.) Create a second folder that will contain your final converted Git project. Once you have created the new folder, right click on the folder and select the TortoiseGit option Git Create repository here option, just like you did previouslyMake sure you do not select the Make It Bear option. Click Ok.

3.) We want to push the Mercurial project to the first, temporary Git folder that we created with the Make It Bear option selected. Right click on the Mercurial project folder and select TortiseHG -> Synchronize from the menu. Select the local repository option from the drop down box and enter the path to your temporary Git folder. Click on the Push button.

4.) Finally, right click on the second Git folder we created and select the Git Sync option. We want to pull the first Git project we created (that we transferred the Mercurial repository to) into this Git repository. Enter the path of the first Git project into the Remote URL text box and click the Pull option. You will now have a Git project.