The Wayback Machine - https://web.archive.org/web/20090710022119/http://github.com:80/blog/439-hg-git-mercurial-plugin
  • Hg-Git Mercurial Plugin

    schacon 27 May 2009

    We hear from a number of people who are using Mercurial for their projects but want to host them on GitHub because they want their project to benefit from the community here. Or perhaps they are in a group where some of the developers want to use Mercurial and others want to use Git and so they just stick with Subversion (ugh). We don’t want to live in a world where developers who are ready to switch to a DVCS end up staying with Subversion.

    So, I’ve been working on a plugin for Mercurial that lets it communicate with a Git server as a native Git client. I give you hg-git!

    This means that if you are a Mercurial developer you can install this plugin and then push and pull to and from Git servers, either GitHub or somewhere else. It is a lossless bi-directional bridge, meaning you can push to a Git server from one Hg user, then another Hg user can clone using this plugin and the node ids will all be identical. It can even handle things like tags, explicit renames, named branches, octopus merges and more.

    The plugin is pretty far along at this point – I’ve been using it for all the hg-git development and I’ve heard from a number of others who are using it successfully even on relatively large projects. It is slow sometimes and may not handle some edge cases well, but the software is rapidly maturing. If you do use it, please let me know about any issues you run into, we want to make this rock solid.

    There are no external dependencies – the library is entirely written in python and contains a pure python implementation of all the Git functionality it needs, so you don’t need to have Git installed locally at all. It has been known to work with Mercurial 1.1 and 1.2 – let me know if you try it with something else.

    Usage

    From Hg with the plugin installed, you can clone a Git repository like this:

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

    Or, if you have an existing Hg repository, you can run something like this:

    $ cd myproject # (an Hg repository)
    $ hg gremote add origin git(at)github.com:schacon/myproject.git
    $ hg gpush

    With those two commands you can basically import your Hg repository into a GitHub repository. Then people can fork and work on your code in Hg or in Git and push back up, then you can pull in any contributed work with something like this:

    $ hg gremote add scott git://github.com/scott/project.git
    $ hg gfetch scott
    $ hg update

    The basic commands the plugin adds to the Hg command library are ‘gclone’, ‘gremote’, ‘gpush’ and ‘gfetch’ – all roughly equivalent to their Git counterparts. Also, running a normal ‘hg clone’ with an identifiable Git protocol (git://, git+ssh://) will fire up ‘gclone’ automatically.

    See the hg-git homepage for more information.

  • Comments

    kballard Wed May 27 19:50:49 -0700 2009

    Cool! But what about the other direction? I'm a git user, but I'd like to be able to benefit from projects hosted in Mercurial.

    defunkt Wed May 27 20:11:51 -0700 2009

    @kballard This is a plugin for hg. What you're talking about sounds more likely to be a plugin for git.

    spicyj Wed May 27 20:24:02 -0700 2009

    So does that mean that we can use TortoiseHg with Git, now?

    pykler Wed May 27 20:28:20 -0700 2009

    @spicyj i think tortoise hg needs to know about the gpush and gpull commands first.

    chergert Wed May 27 23:51:41 -0700 2009

    rockem' sockem' awesome

    seancribbs Thu May 28 05:28:19 -0700 2009

    Some of my favorite projects use Mercurial (webmachine, RabbitMQ). I hope this will encourage them to join the party over here (sorry, bitbucket is not half as cool).

    mariuz Thu May 28 08:21:34 -0700 2009

    what is next bzr ? :)
    i see there is an git import tool for launchpad

    mgeisler Thu May 28 10:39:31 -0700 2009

    @kballard: this is a two-way bridge. By definition, this means that you can now use Git to work on Mercurial projects -- and push to Bitbucket. No need for Github any more :-)

    schacon Thu May 28 12:43:58 -0700 2009

    technically, you can use this to use Git to collaborate on Hg hosted projects - there are 'gimport' and 'gexport' commands that will just do the object translations - but it's a bit more convoluted. i'll try to write up a guide on how to do that at some point after this is all settled down.

    thenduks Mon Jun 01 14:40:20 -0700 2009

    I tried to convert an old project I had in hg to git with mercurial 0.9.5 (like I said, old project :)) and this didn't work, updated to the newest stable (1.2.1) and all was well.

    thenduks Mon Jun 01 14:41:20 -0700 2009

    Oh, and thanks Scott, saved me the hassle of (among other things) going back to this project occasionally and always accidentally typing 'git st' :)

    nathany Tue Jun 02 15:20:24 -0700 2009

    Quite awesome indeed.

    neithere Sun Jun 14 12:46:27 -0700 2009

    This is excellent!! Thanks a lot.

    Isakawa Sat Jun 27 09:48:14 -0700 2009

    sweet how about a tcp acute code

    Please log in to comment.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.