man git-gc
doesn't have an obvious answer in it, and I haven't had any luck with Google either (although I might have just been using the wrong search terms).
I understand that you should occasionally run git gc
on a local repository to prune dangling objects and compress history, among other things -- but is a shared bare repository susceptible to these same issues?
If it matters, our workflow is multiple developers pulling from and pushing to a bare repository on a shared network drive. The "central" repository was created with git init --bare --shared
.
From the
git-gc
man page:Emphasis mine. Bare repositories are repositories too!
Further explanation: one of the housekeeping tasks that
git-gc
performs is packing and repacking of loose objects. Even if you never have any dangling objects in your bare repository, you will -- over time -- accumulate lots of loose objects. These loose objects should periodically get packed, for efficiency. Similarly, if a large number of packs accumulate, they should periodically get repacked into larger (fewer) packs.I do not know 100% about the logic of gc.. but to reason this out:
git gc removed extra history junk, compresses extra history, etc. It does nothing with your local copies of files.
The only difference between a bare and normal repo is if you have local copies of files.
So, I think it stands to reason that YES, you should run git gc on a bare repo.
I have never personally ran it, but my repo is pretty small and is still fast.
The issue with
git gc --auto
is that it can be blocking.But with the new (Git 2.0 Q2 2014) setting
gc.autodetach
, you now can do it without any interruption:See commit 4c4ac4d and commit 9f673f9 (Nguyễn Thái Ngọc Duy, aka pclouds):
Note: only git 2.7 (Q4 2015) will make sure to not loose the error message.
See commit 329e6e8 (19 Sep 2015) by Nguyễn Thái Ngọc Duy (
pclouds
).(Merged by Junio C Hamano --
gitster
-- in commit 076c827, 15 Oct 2015)As Jefromi commented on Dan's answer,
git gc
should be called automatically called during "normal" use of a bare repository.I just ran
git gc --aggressive
on two bare, shared repositories that have been actively used; one with about 38 commits the past 3-4 weeks, and the other with about 488 commits over roughly 3 months. Nobody has manually rungit gc
on either repository.Smaller repository
Larger repository
I wish I had thought of it before I
gc
ed these two repositories, but I should have rungit gc
without the--aggressive
option to see the difference. Luckily I have a medium-sized active repository left to test (164 commits over nearly 2 months).Running
git gc
clearly made a large dent incount-objects
, even though we regularlypush
to andfetch
from this repository. But upon reading the manpage forgit config
, I noticed that the default loose object limit is 6700, which we apparently had not yet reached.So it appears that the conclusion is no, you don't need to run
git gc
manually on a bare repo;* but with the default setting forgc.auto
, it might be a long time before garbage collection occurs automatically.* Generally, you shouldn't need to run
git gc
. But sometimes you might be strapped for space and you should rungit gc
manually or setgc.auto
to a lower value. My case for the question was simple curiosity, though.Some operations run
git gc --auto
automatically, so there should never be the need to rungit gc
, git should take care of this by itself.Contrary to what bwawok said, there actually is (or might be) a difference between your local repo and that bare one: What operations you do with it. For example dangling objects can be created by rebasing, but it may be possible that you never rebase the bare repo, so maybe you don't ever need to remove them (because there are never any). And thus you may not need to use
git gc
that often. But then again, like I said, git should take care of this automatically.