Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to convert Mercurial repository to Git

📅 2019-Sep-20 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ git, mercurial ⬩ 📚 Archive

With Mercurial losing the DVCS race to Git, I had a bunch of Hg repositories that I needed to convert to Git. I did that using the hg-git extension to Mercurial like this:

$ hg clone ssh://

hg-git is available through PyPI, but I had problems when I used it. hg-git is also available on a Github mirror. However, that mirror has not been updated since 2016 and I ran into problems when I used the tool.

hggit = /path/to/hg-git/hggit
hgext.bookmarks =
$ pip install -U --user dulwich
$ git init --bare foobar_git_bare
$ hg bookmarks hg
$ hg push /path/to/foobar_git_bare
$ git clone foobar_git_bare foobar_git

You can change to the foobar_git repository and view all your commits and branches from the old Mercurial repository. This Git repository is now ready for action.

$ git remote remove origin
$ git remote add origin
$ git push --set-upstream origin master

Tried with: Mercurial 4.5.3 and Git 2.17.1

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘📧