Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

bitbucket-hg-to-git - a free Mercurial-to-Git migration script

Following the recent announcement that BitBucket will be 'sunsetting' support for Mercurial repositories from 1/6/20  it became fairly urgent for me to find a straightforward solution to migrate my Hg projects over to Git.

I only have a few projects but an automated approach should be less error-prone and able to preserve project metadata where possible. I therefore created a simple tool to handle my migration needs.

This project is a simple Python 3.7 script that makes use of the BitBucket 2.0 API to identify and create new equivalent Git repositories and a Git/Mercurial compatibility addon to do the conversion.

 I've used it only in a Cygwin environment on Windows but I tried to keep it fairly generic so hopefully it will work anywhere that Python 3 is installed.  I used Python 3.7.4.

It functions approximately as follows:

1) Ensure git and git-remote-hg are available on PATH
2) Connect (authenticate) to BitBucket API
3) Read list of projects for user
4) For each project:
5) If it's not a Mercurial project, skip processing
6) If a Git equivalent project exists already, skip processing
7) Create Git equivalent project on BitBucket
8) Clone project locally using git clone --mirror with hg:: prefix
9) Push local project to new git remote using git push --mirror

For the authentication (2) you should set up a temporary App Password (under your account > Settings > Access Management > App Passwords) with 'Admin' access to your repositories.  You can easily revoke this when done.  I used the following configuration:

Annotation 2019-11-03 093113.png

The script can be found in a Git project bitbucket-hg-to-git and is dedicated to the community.  Please feel free to modify it for your own needs or even raise issues and pull-requests if necessary.


1 comment


How set the slug to work with the repository in a team workspace? We faced the issue when the tool can't find our repository. But we can clone the repo using the same user and app password.



Log in or Sign up to comment
Community showcase
Published in Bitbucket

Powering DevOps with Bitbucket Server & Data Center

Hi everyone, The Cloud team recently announced 12 new DevOps features that help developers ship better code, faster   ! While we’re all excited about the new improvements to Bitbucket ...

2,160 views 0 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you