The popularity of Git continues to grow and, according to Eclipse Community Survey, has surpassed even SVN in the past year.  Git currently holds 33.3% of the market, SVN with 30.7%, and Mercurial at 2.1%.  It has become easy to find developers with in-depth knowledge of Git, while developers with deep knowledge of Mercurial are difficult to find.  With that in mind there are a number of development shops which are making the transition from Mercurial to Git.  In this post I will walk you through the migration from installation to completed migration while avoiding the detours I ran into when I first did a migration from Mercurial to Git.

Setup the tools

Install TortoiseHg from http://tortoisehg.bitbucket.org/

Enable Hg-Git extension

TortoiseHg_Extensions

Open TortoiseHg Workbench, Open the File/Settings menu and make sure the Hg-Git extension is enabled under “Extensions”.

Ready your repository

During the migration from Mercurial to Git, branches will be created in Git for all bookmarks set in Mercurial, including the master branch.

On your client windows computer you will need to bookmark the default branch as master.  This will properly map your trunk from Mercurial to Git when the data is migrated:

For each branch you wish to migrate, execute the following command.  This is a good time to improve branch name consistency, and correct any old branch name issues.


 

Setup Git Server

There are many ways to implement a Git server, from cloud hosting services such as GitHub and ProjectLocker to hosting your own web accessible server such as GitBlit or GitLab, all the way down to just running git-daemon.

My personal preference is to install GitBlit within my local network.  GitBlit offers a very simple all-in-one install option called GitBlit GO (http://gitblit.com/).  GitBlit offers all of the standard Git hosting features from LDAP integration to a web-based administrative interface.  All with an easy to understand configuration file, and step-by-step installation instructions.

Install GitBlit according to the instructions.

Login with the credentials admin/admin.

Open the repositories view.

GitBlit

Create a new Repository.

GitBlit-repositories

Copy the address of the repository for the next step.

GitBlit-sampleRepo
 

Migrate your data

Migration of your Mercurial repository to Git is as simple as using the Hg-Git plugin and doing a push.  In the command below, the “git+” tells Mercurial to use the Hg-Git plugin to communicate with a Git server.  This command will convert all of the change sets to the Git format, and then push them all to the Git server.

 

Git client

Download an install the git client from http://git-scm.com/downloads or a visual client such as TortoiseGit from https://code.google.com/p/tortoisegit/wiki/Download.

Conclusion

Your Git repository is ready to be used.

You now have the option to continue to use your Hg client with the “git+” addition to the repository path, or use your new Git client.