Bitbucket Mercurial to Git Migration
This project was created to share powershell scripts that make it easy to convert hg repositories in Bitbucket to git.
> choco install hg
Clone Hg-Git, which lets hg interact with git repositories:
> hg clone https://bitbucket.org/durin42/hg-git
Enable hg-git in your global Mercurial config file. You can typically find this file at
%USERPROFILE%\mercurial.ini on Windows.
[extensions] hggit = c:/path/to/hg-git/hggit
Get the migration scripts
Clone this repository and make a note of path to the
> git clone https://github.com/jrummell/bitbucket-hg-migration
Execute the migrate script:
> .\migrate.ps1 -BitbucketAccount username -Repository repo-name
- clone the hg repository to
- create a bare git repository at
- push all commits from the hg repository to the git repository
For example, if your hg repository is
https://bitbucket.org/jrummell/bitbucket-hg-migration/, use the following arguments:
> .\migrate.ps1 -BitbucketAccount jrummell -Repository bitbucket-hg-migration
which will clone the hg repository to
.\jrummell\bitbucket-hg-migration-hg, create a new bare git repository at
.\jrummell\bitbucket-hg-migration-git and push to it.
Create your git repository
Create a new git repository in Bitbucket.
> .\push.ps1 -BitbucketAccount username -Repository git-repo-name
- push the local bare git repository created by the migrate script to your new git repository in Bitbucket
Using the same example:
> .\push.ps1 -BitbucketAccount jrummell -Repository bitbucket-hg-migration
will push your new git repository to
These scripts use the following conventions/assumptions:
- You are converting your Bitbucket hg repository to a new git repository in Bitbucket.
- When you create a new git repository, it has the same name as the hg repository.
- You are using SSH keys for authentication with Bitbucket.
For example, I used the following workflow to migrate about a dozen repositories:
- Clone an existing hg repository:
hg clone ssh://email@example.com/jrummell/bitbucket-hg-migration
.\migrate.ps1 -BitbucketAccount jrummell -Repository bitbucket-hg-migration
- Rename the hg repository in Bitbucket to
- Create a new git repository in Bitbucket with the original hg repository name
.\push.ps1 -BitbucketAccount jrummell -Repository bitbucket-hg-migration
If your needs are different, or want different repository names, you can adjust the scripts accordingly, or simply use them as a starting point.
If you want your git repository in GitHub, for example, you could change the push script to push to GitHub instead.
I used the following for references when creating these scripts: