Software Development/Migration_HG_Git

Migrating Mercurial (HG) to Git

Concepts (Read first)

Mercurial has branches (which we have used extensively: one ticket, one branch), and bookmarks (rearely used here). But Git branches really correspond to Mercurial’s bookmarks, while Mercurial’s branches are more like full forks of a Git repository, operated with pull requests among them, but with some added limitations for Mercurial: all “forks” are kept in one place and share a single namespace of bookmarks (i.e. the “real” Git branches).

Thus, it is not totally correct, but technically feasible, to reflect all Mercurial branches into a “principal” (or upstream) Git repository. To accomplish that, every candidate Mercurial branch, will need an auxiliary Mercurial bookmark which is used to track the tip of that branch: a branch named “BRANCH-124-bis” will be bookmarked as “BRANCH-124-bis_git_pEp_fnd”.

The setting in .hg/hgrg for this suffix is:


Install hg-git

First, find out what Python version your Mercurial is using:

hgpy=$(head -n1 $(which hg) | sed 's/^#!//' | tee -a /dev/stderr)
mkdir ~/pep-git-migration
cd ~/pep-git-migration
git clone
#  - or -
hg clone
cd hg-git
"$hgpy" -m pip install --user -e .
"$hgpy" -m pip install brotli ipaddress   # see (*) comment later on

Edit ~/.hgrc to add a line to the extensions section:

${EDITOR-nano} ~/.hgrc

hggit = ~/pep/code/repos/hg-git/hggit

At this point hg help should show an entry “git” (*):

$!hg help
Mercurial Distributed SCM

list of commands:


additional help topics:

 git           Working with Git Repositories

In my case, hg push $git_destination will later complain about missing modules, thus I add them manually earlier:

# "$hgpy" -m pip install brotli ipaddress

Mapping usernames in history: authors.txt

Where authors.txt is the name of a text file containing author name translations, one per each line, using the following format:

johnny = John Smith dougie = Doug Johnson

See if an authors.txt file is necessary:

hg log | grep ^user: | sort | uniq | grep -v \@

[ to be continued ]


For the following authors, name and email have to be defined manually

<name> = Anonymous <>
Alain Leufroy = x y <>
Alexey Sokolov = x y <>
Damiano Boppart = x y <>
David = x y <>
Dean = x y <>
Dean Looyengoed = x y <>
Edouard Tisserant = x y <>
Hussein Kasem = x y <>
Lix = x y <>
Thomas = x y <>
ana = x y <>
berna = x y <>
dulzet = x y <>
edouard = x y <>
fdik = Volker Birk <>
jsumners = x y <>
krista = x y <>
lix = x y <>
nana = x y <>
nikolaj = x y <>
nk = x y <>
vb = Volker Birk <>