Forcing Remote Repo to Compress (GC) with Git

jocull picture jocull · Nov 18, 2010 · Viewed 10.2k times · Source

I'm using Git to version a series of binary files. They compress pretty well, but my central repos do not seem to be compressing when I push to them. They're eating up a decent amount of my quota, so I was looking to see if there was a way to force the remote repo to do a GC.

Is this possible? I'm working on Project Locker so I don't believe I have SSH access to go in and GC the repo myself. Any ideas? Thanks.

Answer

Cascabel picture Cascabel · Nov 18, 2010

If you can't run git gc yourself, you're going to have to trick it into running automatically. You won't have quite such full control over it then, but you should at least be able to get it to run.

git gc --auto is run by several commands; the relevant one here is receive-pack, which is run on the remote to receive a pack as part of a push. gc --auto only repacks when there are enough loose objects; the cutoff is determined by the config parameter gc.auto, and defaults to 6700.

If you have access to the remote's gitconfig, you could set that cutoff to 1 temporarily. There should pretty definitely be at least 1 loose object in the repo, so that should cause gc --auto to do its thing the next time you push.

If you don't have access to the remote's gitconfig, all I can think to do is artificially create a bunch of loose objects. You could do that by creating a branch, committing a bunch of tiny files (with different content) to it, pushing the branch to the remote, then deleting the branch from the remote. (Important to vary the content, or they'll just use the same blobs.) Rinse and repeat.