Mirroring Hg repositories on GitHub

$ hg push github
pushing to git+ssh://git@github.com/krbullock/vlad-merb.git
importing Hg objects into Git
creating and sending data
    github::refs/tags/rel-2.0.0 => GIT:521e1f66
    github::refs/heads/master => GIT:2c352a82
$ _

I’ve been playing with hg-git for the past couple weeks off-and-on (Abderrahim Kitouni’s fork—and so should you). Today I decided to try to use it to provide git mirrors of my projects. It took a bit of futzing around to figure out how to set it up, but as you can see above, it’s smooth like buttah. Here’s how I did it.

        <span id="more-1366"></span>

        <ol>

  • Install hg-git (and dulwich, which it depends on). In a terminal:

    $ wget http://samba.org/~jelmer/dulwich/dulwich-0.3.3.tar.gz
    $ tar xvzf dulwich-0.3.3.tar.gz
    $ (cd dulwich-0.3.3 && sudo /usr/bin/python setup.py install)
    
    
    $ wget -O hg-git.tar.gz http://bitbucket.org/abderrahim/hg-git/get/tip.gz
    $ (cd /path/to/hgext && tar xvzf /path/to/download/hg-git.tar.gz)
    

    Then add hg-git into your ~/.hgrc:

    [extensions]
    hg_git = /path/to/hgext/hg-git
    
  • On GitHub, create a repo for your project.

  • Translate the GitHub clone URL, like this:

    git@github.com:krbullock/vlad-merb.git
    

    into an hg-git-friendly git+ssh URL, like this:

    git+ssh://git@github.com/krbullock/vlad-merb.git
    
  • Put that URL into your Mercurial repository’s hgrc:

    [paths]
    github = git+ssh://git@github.com/krbullock/vlad-merb.git
    
  • Push to GitHub:

    $ hg push github
    
  • Boom. Done. :)


    About this entry