Building simplicidade.org: notes, projects, and occasional rants

git gc --auto

For normal usage, git is written to be as fast as possible. That means that certain house-cleaning tasks are not done on every command and from time to time, you have to let the git gremlins cleanup the place.

For the last couple of git releases, the most common command to do that is to use git gc --auto. This will check the repository, see if it needs cleaning, and perform the necessary operations. Its a safe command, you can even start it, and keep on working on the same repository.

Personally, I run it when I remember or when git gui reminds me that I have to many loose objects.

In case you might be wondering the sort of impact this can have on your repo, I'll quote an extreme case. Notice that the user didn't use git gc --auto but choose a different, more aggressive, set of options. The tradeoff is execution time and you cannot use the repo while git gc runs.

I used git-svn to import a repository with 33000 revisions and about 7500 files. It took about 18 hours to import. When it was done, my .git folder had 242001 files that comprised 2.0GB. I ran git gc --agressive --prune and let that sit overnight (I wish it was more verbose, it went for over an hour without printing anything), and that managed to compress the repo down to 334 files and 64MB.

So from time to time, don't forget to git gc --auto.