Fast Export, from Mercurial to Git

Fast Export is a tool for converting Mercurial repositories to Git repositories.

In order to get Fast Export we should run the following command in the folder you want it.

git clone https://github.com/frej/fast-export.git

The result of cloning this repository should be the following:

fast-export nperez$ ls -l
total 112
-rw-r--r-- 1 nperez IPC\Domain Users 3598 Jun 20 12:22 README.md
-rwxr-xr-x 1 nperez IPC\Domain Users 16901 Jun 20 12:22 hg-fast-export.py
-rwxr-xr-x 1 nperez IPC\Domain Users 4122 Jun 20 12:22 hg-fast-export.sh
-rwxr-xr-x 1 nperez IPC\Domain Users 4721 Jun 20 12:22 hg-reset.py
-rwxr-xr-x 1 nperez IPC\Domain Users 1516 Jun 20 12:22 hg-reset.sh
-rwxr-xr-x 1 nperez IPC\Domain Users 3424 Jun 20 12:22 hg2git.py
-rw-r--r-- 1 nperez IPC\Domain Users 4324 Jun 20 12:25 hg2git.pyc
C02PQHHEG8WP:fast-export nperez$

Now, let’s suppose we have the Mercurial repository we want to convert in the folder: ~/Desktop/subex

We need to create a new folder where the new git repository will live in.

mkdir ~/Desktop/your-new-git-repo
cd ~/Desktop/your-new-git-repo

After that, we need to initialize a git repository in the location of our new git repository by running:

git init

Now, we are ready to export the Mercurial repository:

~/fast-export/hg-fast-export.sh -r ~/Desktop/your-mercurial-repo

Make sure you pass -r as a option to the command.

Once the export process ends, checkout the new git repository or you won’t be able to see anything on the folder.

git checkout

From here, you should proceed to add the a handler to the remote repository. This can be done on command line interface:

git remote add origin https://your-host/repo.git

By this time we have a git repository that contains all the history from mercurial including tags. Just push your new git repository to it’s remote and you are ready to go.

git push origin --all

If you want to do this even easier, make a bash script with all the commands we just saw and have fun converting your mercurial repositories to git!