descriptionPrograms to feed git-fast-import
last changeTue, 13 Feb 2018 13:37:58 +0000 (13 13:37 +0000)
content tags

hg-fast-export.(sh|py) - mercurial to git converter using git-fast-import

Most hg-* scripts are licensed under the [MIT license] ( and were written by Rocco Rutte <> with hints and help from the git list and #mercurial on freenode. is licensed under GPLv2 since it copies some code from the mercurial sources.

The current maintainer is Frej Drejhammar <>.


If you have problems with hg-fast-export or have found a bug, please create an issue at the [github issue tracker] ( Before creating a new issue, check that your problem has not already been addressed in an already closed issue. Do not contact the maintainer directly unless you want to report a security bug. That way the next person having the same problem can benefit from the time spent solving the problem the first time.


Using hg-fast-export is quite simple for a mercurial repository <repo>:

mkdir repo-git # or whatever
cd repo-git
git init -r <local-repo>
git checkout HEAD

Please note that hg-fast-export does not automatically check out the newly imported repository. You probably want to follow up the import with a git checkout-command.

Incremental imports to track hg repos is supported, too.

Using hg-reset it is quite simple within a git repository that is hg-fast-export'ed from mercurial: -R <revision>

will give hints on which branches need adjustment for starting over again.

When a mercurial repository does not use utf-8 for encoding author strings and commit messages the -e <encoding> command line option can be used to force fast-export to convert incoming meta data from <encoding> to utf-8. This encoding option is also applied to file names.

In some locales Mercurial uses different encodings for commit messages and file names. In that case, you can use --fe <encoding> command line option which overrides the -e option for file names.

As mercurial appears to be much less picky about the syntax of the author information than git, an author mapping file can be given to hg-fast-export to fix up malformed author strings. The file is specified using the -A option. The file should contain lines of the form "<key>"="<value>". Inside the key and value strings, all escape sequences understood by the python string_escape encoding are supported. (Versions of fast-export prior to v171002 had a different syntax, the old syntax can be enabled by the flag --mappings-are-raw.)

The example below will translate User <garbage<tab><> to User <>.

-- Start of --
"User <garbage\t<>"="User <>"
-- End of --

Tag and Branch Naming

As Git and Mercurial have differ in what is a valid branch and tag name the -B and -T options allow a mapping file to be specified to rename branches and tags (respectively). The syntax of the mapping file is the same as for the author mapping.


hg-fast-export supports multiple branches but only named branches with exactly one head each. Otherwise commits to the tip of these heads within the branch will get flattened into merge commits.

As each git-fast-import run creates a new pack file, it may be required to repack the repository quite often for incremental imports (especially when importing a small number of changesets per incremental import).

The way the hg API and remote access protocol is designed it is not possible to use hg-fast-export on remote repositories (http/ssh). First clone the repository, then convert it.

Design was designed in a way that doesn't require a 2-pass mechanism or any prior repository analysis: if just feeds what it finds into git-fast-import. This also implies that it heavily relies on strictly linear ordering of changesets from hg, i.e. its append-only storage model so that changesets hg-fast-export already saw never get modified.

Submitting Patches

Please use the issue-tracker at github to report bugs and submit patches.

2018-02-13 ceqiUpdate usage section example commandsmaster
2018-02-01 Frej DrejhammarWarn contributors from doing work that will no be merged
2018-01-24 Martin FreundQuote $PYTHON variable to support paths with spacesv180126
2017-10-02 Frej DrejhammarChange syntax of mapping filesv171002
2017-09-29 Frej DrejhammarRefactor load_mapping() to move line parsing to inner...
2017-08-25 Frej DrejhammarAvoid nuisance error printout from readlink testv170826
2017-08-18 Frej DrejhammarDon't break if the destination directory name contains... add-missing-quotev170818
2017-06-24 Frej DrejhammarEliminate bashismv170624
2017-06-05 Frej DrejhammarBehave nicely when the found readlink does not understa... v170617
2017-06-02 Frej Drejhammardocumentation: Point users to the issue tracker for... v170604
2017-06-02 Felix AlthausMake callable via a symbolic link
2017-05-14 Frej DrejhammarFix crash when a branch name starts with '/'
2017-01-01 Emilian BoldShow warning when core.ignoreCase is truev170101
2016-12-28 Frej DrejhammarMake backup copies of state files
2016-10-01 Frej DrejhammarFix broken support for bare repositories
2016-09-14 Frej DrejhammarDo not rely on git internals, support Git >= 2.10v160914
7 weeks ago v180126 v180126
5 months ago v171002 v171002
6 months ago v170826 v170826
6 months ago v170818 v170818
8 months ago v170624 v170624
9 months ago v170617 v170617
9 months ago v170604 v170604
14 months ago v170101 v170101
18 months ago v160914 v160914
18 months ago v160415 Tag version 160415
4 weeks ago master
6 months ago add-missing-quote
10 years ago git-p4
10 years ago hanwen
Cached version (2372s old) 
fast-export/rorcz.git Local fork with needed fixes 16 months ago
fast-export/benizi.git 5 years ago
fast-export/fast-export-unix-compliant.git dereckson@espace... 5 years ago
fast-export/dharding.git 5 years ago
fast-export/barak.git tweaks and maybe debian packaging info 6 years ago