Recently Atlassian has removed support for the Mercurial version control system from Bitbucket Cloud and its application programming interface (API). As such, users can’t use Mercurial features in Bitbucket or via its API, and all Mercurial repositories will be removed. These changes are forcing teams to migrate their existing Mercurial repositories to another version control system such as Git, which is the most recommended option.
There are various Git conversion tools available in the market, including hg-fast-export and hg-git mercurial plugin. However, there are not many resources available for the teams to learn the migration process from Mercurial to Git. Infostretch has created this guide to help organizations with their Mercurial to Git migration, based on our experience of migrating more than 130 repositories.
By migrating more than 130 Mercurial repositories between 100 MB and 2 GB, Infostretch has developed the following guidelines:
- Install Mercurial 4.6.1 from https://www.npackd.org/p/com.selenic.mercurial.Mercurial/4.6.1
- Install Python 2.7.16 from https://www.python.org/downloads/release/python-2716/
- Install Git for Windows. Visit https://git-scm.com/ to download and install
the latest release of Git to your environment.
- Create a new Git empty repository (without any ReadMe file).
Steps to perform the conversion from Mercurial repo to Git repo
- After the successful installation of Python, you will have a folder for the same in C:\Python27.
- Add Python to PATH. To do this, Go to This PC then right-click, Properties -> Advance System Setting ->
Advanced Tab -> Click on Environment Variables.
- Click on New in System variable. Add “Python” in Variable name and “C:\Python27; C:\Python27\DLLs;
C:\Python27\Lib; C:\Python27\Lib\lib-tk; C:\Python27\libs; C:\Python27\Scripts; C:\Python27\tcl;
C:\Python27\Tools” in Variable Value.
- In User Variable, edit the path and add C:\Python27 also. Now open CMD and type PATH and check if C:\Python27 is
- Create a folder named Projects and two folders inside of Projects as Git and Mercurial.
- Clone your Mercurial repository in Mercurial path. You can do this using a source tree or from CMD. Open CMD and
hg clone https:// bitbucket.org/my-ondemand/mercurial_test
- Clone your Git repository in the Git path. You need to execute the following commands in CMD:
git clone https://bitbucket.org/my-ondemand/microservice_invoicing_gitrepo.git
- Install Mercurial with the following commands from CMD:
pip install mercurial
- Clone hg-fast-export repository:
git clone https://github.com/frej/fast-export.git
- Copy the content of fast-export into the microservice_invoicing folder except .git folder.
- Execute the command for hg-fast-export: Open Git Bash terminal from microservice_invoicing and run the following
env PYTHON=python ‘c:\Projects\Git\microservice_invoicing\hg-fast-export.sh’ -r‘c:\Projects\Mercurial\microservice_invoicing_test’ -–force
Only complete the following steps if you are NOT going to use POWERSHELL script created for Git commands
- Run following commands in CMD from the newly created Git folder to checkout git and remove unwanted files:
git clean -f
//fire below command in POWERSHELL from Git project location// i.e., c:\Projects\Git\ microservice_invoicing
Remove-Item ‘plugins’ -recurse -force
Remove-Item ‘pluginloader’ -recurse -force
- Rename .hgignore to .gitignore in CMD from Git project location i.e. c:\Projects\Git\
ren .hgignore .gitignore
git add .gitignore
git commit -m “.hgignore renamed to .gitignore”
- Perform an initial commit in the Git bash terminal from Git project location (i.e., c:\Projects\Git\
git commit -m “.hgignore and .hgflow removed”
- For each Git branch, push the branch in the Git bash terminal
git push origin –all
Only complete the following steps if you ARE USING Powershell script created for Git commands
- Open Powershell script in Notepad++. In the “Set-Location” variable, assign your local path of Git repository
i.e., c:\Projects\Git\ microservice_invoicing and save.
- Open the Powershell command prompt and give the path of your Powershell script by entering the command: &
These steps will help you and your team migrate your source codes without losing the code lines that you’ve worked diligently to create. If you need additional help with migration or development work, get in touch with Infostretch today using the form below.