Erik’s Brain

The reward of a thing well done...

Compressing Git Repository

I recently moved a decent sized project from Mercurial to Git, using the method Dan Benjamin outlined here. I noticed that the .hg repo was 88.3MB while the .git repo was 141.3MB. That’s quite an inflation. So I ran git gc to try to compress the repo. That didn’t change a thing. However, running git gc --aggressive got the .git repo down to 78.5MB. Nice! Assuming that the repo still works without any problems :) To my knowledge, the care and feeding that Git requires is one of the few drawbacks of Git compared to Mercurial. But I’m plowing forward with Git. I like how it handles branches better than Mercurial and branches are something I want to use more often. Also, everyone is using Git, and this is one area where it doesn’t really pay to be different. Just go with the flow and life will be a little bit easier.

Update: Sunday, April 1, 2012

I just ran it on the Git repo for Splitcaster, which I also ported over from Mercurial. The repo was 14.4MB and after running git gc --aggressive it was down to 8.5MB. Not nearly the same level of savings, but still nice. But, crap, I forgot to note the difference in the number of files in the repo before and after.

Related: Git Compression