tags:

views:

1970

answers:

7

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?

+9  A: 

It depends mostly on how much the respository is used. With one user checking in once a day and a branch/marge/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.

Adam Davis
A: 

Drop it in a cron job that runs every night (afternoon?) when you're sleeping.

Pat Notz
A: 

I just do it whenever I think about it. That tends to be once every week or two.

Kevin Ballard
A: 

Related question: Does git-gc interfere with the ability to do git push origin master?

(Am I allowed to post related questions or should they be separate?)

Swaroop C H
No, `git gc` will only remove dangling commits (i.e. commits that can't be reached by any reference).
Kevin Ballard
+1  A: 

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

Rory
+1  A: 

Recent versions of git run gc automatically when required, so you shouldn't have to do anything. See the Options section of man git-gc(1): "Some git commands run git gc --auto after performing operations that could create many loose objects."

mrowe
+5  A: 

Note that the downside of garbage-collecting your repository is that, well, the garbage gets collected. As we all know as computer users, files we consider garbage right now might turn out to be very valuable three days in the future. The fact that git keeps most of its debris around has saved my bacon several times – by browsing all the dangling commits, I have recovered much work that I had accidentally canned.

So don’t be too much of a neat freak in your private clones. There’s little need for it.

OTOH, the value of data recoverability is questionable for repos used mainly as remotes, eg. the place all the devs push to and/or pulled from. There, it might be sensible to kick off a GC run and a repacking frequently.

Aristotle Pagaltzis