How do I convert a Bitbucket Mercurial repository (Hg repository) to a Git repository? I want to keep branches and commit history.
I found https://github.com/frej/fast-export which correctly migrates Mercurial branches to Git branches (in contrast to hg-git which only works with Mercurial bookmarks).
Fast-export works on a local (copy of the) repo so it's not purely online. Fast-export has instructions how to create a new local Git repo and populate it.
In my case, I had left some multiple branch heads in Mercurial, giving this error:
Error: repository has at least one unnamed head: hg r493
I could use "hg strip 493" or do a merge to get rid of these heads.
I also had to fix the author fields of some commits, using an "authors file" and the -A switch to fast-export to map the ill-formatted author fields, as described in the README.
Afterwards fast-export accepted the repo.
You also need to create a new Bitbucket repository through the Bitbucket web interface.
Then push to Bitbucket. This example sets up using already configured SSH:
git remote add origin git@bitbucket.org:/
git push --all origin