How often should you use git-gc?
The manual page simply says:
Users are encouraged to run this task on a regular basis within each repository to maintain good disk space utilization and good operating performance.
Are there some commands to get some object counts to find out whether it's time to gc?
If you're using Git-Gui, it tells you when you should worry:
The following command will bring a similar number:
Except, from its source, git-gui will do the math by itself, actually counting something at
.git/objects
folder and probably brings an approximation (I don't knowtcl
to properly read that!).In any case, it seems to give the warning based on an arbitrary number around 300 loose objects.
I use when I do a big commit, above all when I remove more files from the repository.. after, the commits are faster
This quote is taken from; Version Control with Git
Drop it in a cron job that runs every night (afternoon?) when you're sleeping.
I use git gc after I do a big checkout, and have a lot of new object. it can save space. E.g. if you checkout a big SVN project using git-svn, and do a git gc, you typically save a lot of space
It depends mostly on how much the repository is used. With one user checking in once a day and a branch/merge/etc operation once a week you probably don't need to run it more than once a year.
With several dozen developers working on several dozen projects each checking in 2-3 times a day, you might want to run it nightly.
It won't hurt to run it more frequently than needed, though.
What I'd do is run it now, then a week from now take a measurement of disk utilization, run it again, and measure disk utilization again. If it drops 5% in size, then run it once a week. If it drops more, then run it more frequently. If it drops less, then run it less frequently.