Converting a mercurial repo to git

by Kenneth Kalmer on May 3, 2008

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.

2 comments

[...] looks different – there are some ways to convert hg to git  http://hg-git.github.com/ or fast-export. I’ll try these converter – projects after EclipseCon to provide redView’s and [...]

by using a DVCS: EGit (Git) or HgEclipse (Mercurial) « ekkes-corner: eclipse | osgi | mdsd | erp on March 15, 2010 at 9:39 pm. #

Perfect!

by Dilip M on May 21, 2010 at 2:39 am. #

Leave your comment

Required.

Required. Not published.

If you have one.