Moving Mercurial Repository from BitBucket to GitHub

I already wrote once about moving from Mercurial to Git. That was way back in 2015 when I moved most of my repositories. However, I didn't move all. Quite a few old electronics projects remained on BitBucket, my Mercurial home of choice. With BitBucket removing Mercurial starting June 1st, it was time to move remainder.

First you will need Ubuntu Linux with a few tools.

Terminal
sudo apt install --yes git mercurial wget

mkdir ~/bin
wget https://raw.github.com/felipec/git-remote-hg/master/git-remote-hg -O ~/bin/git-remote-hg
chmod +x ~/bin/git-remote-hg

Here the git-remote will do most of the heavy lifting as it will enable cloning of Mercurial repository (if it fails, try adding --config format.sparse-revlog=0 option):

Terminal
git clone hg::ssh://hg@bitbucket.org/user/project

With repository now in Git format, we can treat it as any other repository and push it to our server. In the case of GitHub, that would look something like this:

Terminal
git remote rm origin
git remote add origin git@github.com:user/project.git
git push --all

That's all. Rinse and repeat until there is no Mercurial repo left.

PS: Considering how great Mercurial is for beginners, I am sad to see it's primary online home gone. There are other places allowing hosting of Mercurial repositories but BitBucket was among first and it actually worked remarkably well.

PPS: Yes, this works for local repositories too.

Leave a Reply

Your email address will not be published. Required fields are marked *