I have tried many different ways of converting Mercurial (Hg) repositories to Git repositories. Some of them didn't work, some of them worked, and some of them, well, worked better.
Here is my favourite method, assuming you are using Linux (I was running Ubuntu). If you are not running Linux, I seriously recommend running it on a virtual machine just because it is easier to manipulate repositories that way.
Firstly, download the
hggit plugin for Mercurial. Don't get this confused with the
githg plugin (which has similar, but different, functionality).
$ sudo aptitude install mercurial-git
Now, you have to add a few lines to your global Mercurial config file (
~/.hgrc) so that Mercurial will load the
hggit plugin next time you use it.
[extensions] hggit =
Now, navigate to the root directory of your Mercurial repo that you wish to convert, and run the following command, which adds a
master branch to the repo, so that it is Git-compatible.
$ hg bookmark -r default master
Now, all you have to do is push to your empty Git repository, using the standard Mercurial push command! The hggit plugin automatically converts it for you as part of the push command. For example, if you were pushing to a newly created repository on GitHub,
$ hg push git+ssh://email@example.com:username/projectname.git
You don't have push to GitHub, you can push to any Git repo, including those on BitBucket, or one you have created on you computer (using the command $ git init in an empty directory).
Note that you must have set up SSH keys on GitHub for this to work correctly. If you haven't, go here and find out how.
- Git Submodules
- Managing Large Repos
- Git Quickstart Guide
- Mercurial Speed Guide
- Git Ignore For Visual Studio