the Hg-Git mercurial plugin

This is the Hg-Git plugin for Mercurial, adding the ability to push to and pull from a Git server repository from Mercurial. This means you can collaborate on Git based projects from Mercurial, or use a Git server as a collaboration point for a team with developers using both Git and Mercurial.

Warning, this software is still beta. It is basically feature complete and pretty stable now, but there are still some edge cases we don't handle well yet and it may be slow in some circumstances. The user interface is also still subject to change. However, there are now a lot of people using it effectively, so please do use it and let me know if you run into anything.

The Big Idea

The Hg-Git plugin can convert commits/changesets losslessly from one system to another, so you can push via a Mercurial repository and another Mercurial client can pull it and their changeset node ids will be identical - Mercurial data does not get lost in translation.

It is intended that Hg users may wish to use this to collaborate even if no Git users are involved in the project, as it may provide some advantages if you're using Bookmarks (it will transfer bookmarks on push, which Mercurial doesn't do).

Commands

You can clone a Git repository from Mercurial by running hg clone [url]. It will create a directory with the same name as the last path component. For example, if you were to run hg clone git://github.com/schacon/munger.git it would clone the repository down into the directory 'munger.git', then convert it to a Mercurial repository for you.

hg clone git://github.com/schacon/munger.git

If you are starting from an existing Mercurial repository, you have to setup a Git repository somewhere that you have push access to, and then run hg push [path] from within your project. For example:

$ cd hg-git # (a Mercurial repository)
$ hg bookmark -r default master # make a bookmark of master for default, so a ref gets created
$ hg push git+ssh://git@github.com/schacon/hg-git.git
$ hg push

This will convert all our Mercurial data into Git objects and push them up to the Git server. You can also put that path in the [paths] section of .hg/hgrc and then push to it by name.

Now that you have a Mercurial repository that can push/pull to/from a Git repository, you can fetch updates with hg pull.

$ hg pull

That will pull down any commits that have been pushed to the server in the meantime and give you a new head that you can merge in.

Installing

The easy way

Run easy_install hg-git, then add make sure the following is in your ~/.hgrc:

[extensions]
hgext.bookmarks =
hggit = 

...and that's it!

The more involved way

First, install version 0.4.0 or newer of dulwich. You can do easy_install 'dulwich>=0.4.0' if you have setuptools installed. Clone this repository somewhere, or download a snapshot, then make the 'extensions' section in your '~/.hgrc' file look something like this:

[extensions]
hgext.bookmarks =
hggit = [path-to]/hg-git/hggit

That will enable the Hg-Git extension for you. The bookmarks section is not compulsory, but it makes some things a bit nicer. Bookmarks will be translated to git heads when pushing.

Dependencies

This plugin is implemented entirely in Python - there are no Git binary dependencies, you do not need to have Git installed on your system. There are in fact no external dependencies currently other than Mercurial and Dulwich. The plugin is known to work on Mercurial 1.3. Versions 1.1 and 1.2 of Mercurial should be supported, but that support hasn't been well-tested in a while.

This plugin was developed by the folks at GitHub