Moving from Subversion to Mercurial and Bitbucket

I've been using Mercurial for source control on my own small projects for a while and have really liked it. I've also wanted to stop supporting my own Subversion server, but previously I've found hosted solutions too expensive. That's why I like Bitbucket's pricing structure. I have lots of projects that need source control, but I either work alone or as part of a small team. Bitbucket charges by the team size, not the number of projects (which seems like a much better way to judge the budget of a project) and it's free for teams of 5 or under.

I've wanted to move my existing subversion projects over to Bitbucket, but I thought that keeping the revision history would be too difficult. Turns out that it was really simple.

  • Step 1: Enable hg convert
    Assuming you've already installed mercurial command line or as I prefer Tortoise HG GUI on your computer you can enable this extension by finding mercurial.ini in your user directory and adding the following lines:
    [extensions]
    hgext.convert =
  • Step 2: Install hgsubvversion extension
    The easiest way to do this is to clone the repository and copy the files into a folder here ~Program Files\TortoiseHg\extensions\hgsubversion
  • Step 3: Create a new mercurial repository in bitbucket
    Use bitbucket's web interface to create a new repository.
  • Step 4: Clone this locally on your machine
    Use either tortoise or the command line to clone this empty repository:
    hg clone https://{bitbucket-username}@bitbucket.org/{bitbucket-username}/{bitbucket-repository-name} {local-directory-name}
  • Step 5: Get revisions from your subversion repository
    Use the command line to use the convert extension, then update your local copy:
    hg convert {svn-repository} {local-directory-name}
    cd {local-directory-name}
    hg update
  • Step 6: Push all these revisions to your bitbucket repository
    hg push
  • Step 7: Set up aliases
    The usernames used by Mercurial and Bitbucket will not match those imported from Subversion. The easiest way to fix this is using aliases in bitbucket. On the commits screen any unknown user has a little question mark by it. Clicking on that lets you alias that username to a Bitbucket user.

That's it.

The hg convert command can do fancier stuff, like renaming branches and changing usernames, but I've found that I don't really need that.