How I Migrated SharpSnmpLib From Mercurial to Git

There are tons of articles on this topic. Here I just summarized what I have done.

Generate Local Git Repository via Hg-Git

The Mercurial repository of #SNMP is at d:\sharpsnmplib

I am on Windows 7 and using the latest TortoiseHg. In this case I have to roll back to TortoiseHg 2.0.5 (because Hg-Git does not support latest Hg) first.

Then I install Hg-Git following However,

  • TortoiseHg 2.0.5 does have Dulwich, so I don’t need to install it right now.
  • So I can go to step 3 directly, and clone the Mercurial repository of Hg-Git from to d:\temp\hg-git
  • Then I modified d:\sharpsnmplib\.hg\hgrc to include the following lines,

    hgext.bookmarks =
    hggit = d:\temp\hg-git\hggit

You can now try to push to GitHub in d:\sharpsnmplib by executing hg push git+ssh://[email protected]/schacon/hg-git.git.

Troubleshooting Issues

This push may fail due to an SSH error. In that case assuming you have set up Git following this guide, you may install TortoiseGit, and launch puttygen.exe from its installation folder to load your private key. Then you can save the key in PuTTY format (.ppk) and launch pageant.exe from TortoiseHg installation folder so as to add this new key. After that you can push again to see if everything works fine.

In my case it failed with an invalid parameter error which I cannot address. But the local Git repository is ready in d:\sharpsnmplib.hg\git

Consolidate Local Git Repository

To be safe, I used TortoiseGit to create an empty Git repository at d:\temp\sharpsnmplib. Then I copy d:\sharpsnmplib.hg\git to d:\temp\sharpsnmplib.git.

Next I followed to perform the housekeeping at d:\temp\sharpsnmplib,

git fsck --full
git prune
git gc --aggressive

If you don’t know how to find git command, you may read

Upload to GitHub

Finally I went to GitHub to create a repository. It is time to upload everything to it,

git push --mirror --progress [email protected]:lextudio/sharpsnmplib.git

Remaining Issues

If you use branching heavily, then you may experience more issues like me. Here are my fixes,

1. Unnamed Branches

Use TortoiseGit to show log on d:\temp\sharpsnmplib and I can see unnamed branches (the branch names seem to be removed during conversion). To rename them, we can simply create new branches in the log view, .

2. Messy Committers and Authors

I was not able to find a suitable way to clean up them without breaking the repository, so I decided to leave it as it was. This is bit of expected after Subversion to Mercurial to Git migration.

© Lex Li. All rights reserved. The code included is licensed under CC BY 4.0 unless otherwise noted.

© - Lex Li. All rights reserved.

Using the Chirpy theme for Jekyll.

Last updated on June 24, 2024