Converting a mercurial repo to git

Keeping with the exodus from SVN/Mercurial to git, here is a super quick guide for converting a Mercurial repo to git.

  1. Get the fast-export script via git:

    git clone git://repo.or.cz/fast-export.git

  2. Make a new (empty) git repo for the project that is currently in Mercurial

    git init projectname.git

  3. Use fast-export to do the convertion

    $ cd projectname.git
    $ /path/to/fast-export.git/hg-fast-export.sh -r /path/to/project.hg
    git checkout master
    
  4. (Optionally) use rsync to bring over uncommitted changes

    rsync -av --delete-after --exclude=.git --exclude=.hg /path/to/project.hg /path/to/project.git

  5. Enjoy your new git repo :)

I’ve only followed these steps on projects that are in their infancy, and were used as Mercurial experiments. I’m not sure how well branches and tags will be handled by the script. Any feedback would be welcome.

Flattr this!

Welcome to the Open Sourcery Archives. These are my older blog posts, from days gone by. I'm keeping them up as part of the historical record. That, and I'm strangely sentimental about them. Please keep in mind that things most certainly have changed since these articles were written, links to external sites might be broken, and general thinking might have changed.

Regardless of all this, I hope you enjoy your stay!

comments powered by Disqus