Wiki
Clone wikiBitBucket Hg to Git / Running
Usage
To run bbhg2git
- Ensure that you have the following pre-requisites installed and on your PATH:
- git
- hg
- python 3 (I used 3.7.4)
- felipec/git-remote-hg (save to any convenient directory on your PATH eg.
~/bin
)
- Either clone the project or just directly download the script src/bbhg2git.py to some convenient directory.
- Ensure that execute permission is set on
bbhg2git.py
and either run it directly or via the Python (version 3) executable as follows:
The ‘-h’ option prints usage help:
$ python3 src/bbhg2git.py -h usage: bbhg2git.py [-h] -u USER -p PASSWORD [-w WORKDIR] [--https] [-a] [slug [slug ...]] Migrate BitBucket Mercurial repositories to Git positional arguments: slug List of repository 'slugs' to be converted optional arguments: -h, --help show this help message and exit -u USER, --user USER BitBucket username -p PASSWORD, --password PASSWORD BitBucket password -w WORKDIR, --workdir WORKDIR Work directory for conversions (default:'work') --https use https:// instead of ssh:// for repository cloning -a, --all Find and convert ALL Mercurial repositories Recommend using a BitBucket App password for the migration - not your login password. Please read https://bitbucket.org/edrandall/bitbucket-hg-to-git/wiki/Home for more information.
The --workdir option defaults to ‘work’ so you can omit it. The ‘work’ directory is created if it doesn’t exist, it is used for cloning Hg projects whence they are mirrored back to new repositories in BitBucket. You can inspect the contents or just delete it afterwards.
For the --password option 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:
Convert a single repository
You need to know the repositry 'slug', which is the last part of the name on its URL.
eg. I have a project named 'My Tutorials Fork'.
Its URL is https://bitbucket.org/edrandall/my-tutorials-fork/
.
Its slug is my-tutorials-fork
.
$ bbhg2git.py -u edrandall -p WxYzAcBdEfGhIjKlMnOp my-tutorials-fork ... Existing repository: edrandall/my-tutorials-fork my-tutorials-fork my tutorials fork New Git repository: edrandall/my-tutorials-fork-git my-tutorials-fork-git my tutorials fork (git) [2019-11-03T23:53:47.578079] Creating new Git repository:my-tutorials-fork-git [2019-11-03T23:53:48.713764] postURI [https://api.bitbucket.org/2.0/repositories/edrandall/my-tutorials-fork-git] response code:200 [2019-11-03T23:53:48.738994] Migrating from hg::ssh://hg@bitbucket.org/edrandall/my-tutorials-fork to git::git@bitbucket.org:edrandall/my-tutorials-fork-git.git ... ... [2019-11-03T23:55:01.325641] Repository edrandall/my-tutorials-fork conversion succeeded. [2019-11-03T23:55:01.325730] Converted 1 repositories.
Convert all my repositories
bbhg2git can identify all of your Hg repositories so you don't need to list all of the slugs.
$ bbhg2git.py -u edrandall -p WxYzAcBdEfGhIjKlMnOp --all ... [2019-11-03T23:55:01.325730] Converted 16 repositories.
SSH keys not configured
By default bbhg2git prefers to use Git with the 'ssh' protocol over 'https'. It's simpler, your password is kept secure, I highly recommend this for all Git usage.
If for some reason you can't set up ssh keys, for example you are behind a firewall which blocks ssh, you may need to force it to use 'https' with the --https
option.
Updated