As you may know Bitbucket is sunsetting Mercurial support, so this is a perfect time to understand how to convert a Mercurial repository to Git. Here I’ll show how to do it very quickly on Ubuntu 18.04.
Clone the fast-export tool, in this example I will clone it in my home directory:
git clone git://repo.or.cz/fast-export.git ~/fast-export
cd ~/fast-export
git checkout v180317
The last step is needed to downgrade fat-export to version v180317, due to a bug that broke support for Mercurial < 4.6.
Create your new Git repository, of course this will be empty at first:
git init my_project
Go inside the new Git repository and use the fast-export tool to migrate your Mercurial repo to Git:
cd my_project
~/fast-export/hg-fast-export.sh -r /path/to/old/mercurial/repo
git checkout HEAD
Now you can go in the Settings of your Bitbucket Mercurial repository and change its name; for example renaming “my_project” to “my_project_hg”. Then you can create a new Git repository on Bitbucket with the same name as your old one.
Finally you can push your new local Git repository to Bitbucket:
git remote add origin [email protected]:yourname/my_project.git
git push -u origin master
With these easy steps I shown you how to convert a Mercurial repository to Git. Happy hacking!