6 git-gc - Cleanup unnecessary files and optimize the local repository
12 'git gc' [--aggressive] [--auto] [--quiet] [--prune=<date> | --no-prune] [--force] [--keep-largest-pack]
16 Runs a number of housekeeping tasks within the current repository,
17 such as compressing file revisions (to reduce disk space and increase
18 performance), removing unreachable objects which may have been
19 created from prior invocations of 'git add', packing refs, pruning
20 reflog, rerere metadata or stale working trees. May also update ancillary
21 indexes such as the commit-graph.
23 When common porcelain operations that create objects are run, they
24 will check whether the repository has grown substantially since the
25 last maintenance, and if so run `git gc` automatically. See `gc.auto`
26 below for how to disable this behavior.
28 Running `git gc` manually should only be needed when adding objects to
29 a repository without regularly running such porcelain commands, to do
30 a one-off repository optimization, or e.g. to clean up a suboptimal
31 mass-import. See the "PACKFILE OPTIMIZATION" section in
32 linkgit:git-fast-import[1] for more details on the import case.
38 Usually 'git gc' runs very quickly while providing good disk
39 space utilization and performance. This option will cause
40 'git gc' to more aggressively optimize the repository at the expense
41 of taking much more time. The effects of this optimization are
42 mostly persistent. See the "AGGRESSIVE" section below for details.
45 With this option, 'git gc' checks whether any housekeeping is
46 required; if not, it exits without performing any work.
48 See the `gc.auto` option in the "CONFIGURATION" section below for how
51 Once housekeeping is triggered by exceeding the limits of
52 configuration options such as `gc.auto` and `gc.autoPackLimit`, all
53 other housekeeping tasks (e.g. rerere, working trees, reflog...) will
58 When expiring unreachable objects, pack them separately into a
59 cruft pack instead of storing the loose objects as loose
63 Prune loose objects older than date (default is 2 weeks ago,
64 overridable by the config variable `gc.pruneExpire`).
65 --prune=now prunes loose objects regardless of their age and
66 increases the risk of corruption if another process is writing to
67 the repository concurrently; see "NOTES" below. --prune is on by
71 Do not prune any loose objects.
74 Suppress all progress reports.
77 Force `git gc` to run even if there may be another `git gc`
78 instance running on this repository.
81 All packs except the largest pack and those marked with a
82 `.keep` files are consolidated into a single pack. When this
83 option is used, `gc.bigPackThreshold` is ignored.
88 When the `--aggressive` option is supplied, linkgit:git-repack[1] will
89 be invoked with the `-f` flag, which in turn will pass
90 `--no-reuse-delta` to linkgit:git-pack-objects[1]. This will throw
91 away any existing deltas and re-compute them, at the expense of
92 spending much more time on the repacking.
94 The effects of this are mostly persistent, e.g. when packs and loose
95 objects are coalesced into one another pack the existing deltas in
96 that pack might get re-used, but there are also various cases where we
97 might pick a sub-optimal delta from a newer pack instead.
99 Furthermore, supplying `--aggressive` will tweak the `--depth` and
100 `--window` options passed to linkgit:git-repack[1]. See the
101 `gc.aggressiveDepth` and `gc.aggressiveWindow` settings below. By
102 using a larger window size we're more likely to find more optimal
105 It's probably not worth it to use this option on a given repository
106 without running tailored performance benchmarks on it. It takes a lot
107 more time, and the resulting space/delta optimization may or may not
108 be worth it. Not using this at all is the right trade-off for most
109 users and their repositories.
114 The below documentation is the same as what's found in
115 linkgit:git-config[1]:
117 include::config/gc.txt[]
122 'git gc' tries very hard not to delete objects that are referenced
123 anywhere in your repository. In particular, it will keep not only
124 objects referenced by your current set of branches and tags, but also
125 objects referenced by the index, remote-tracking branches, reflogs
126 (which may reference commits in branches that were later amended or
127 rewound), and anything else in the refs/* namespace. Note that a note
128 (of the kind created by 'git notes') attached to an object does not
129 contribute in keeping the object alive. If you are expecting some
130 objects to be deleted and they aren't, check all of those locations
131 and decide whether it makes sense in your case to remove those
134 On the other hand, when 'git gc' runs concurrently with another process,
135 there is a risk of it deleting an object that the other process is using
136 but hasn't created a reference to. This may just cause the other process
137 to fail or may corrupt the repository if the other process later adds a
138 reference to the deleted object. Git has two features that significantly
139 mitigate this problem:
141 . Any object with modification time newer than the `--prune` date is kept,
142 along with everything reachable from it.
144 . Most operations that add an object to the database update the
145 modification time of the object if it is already present so that #1
148 However, these features fall short of a complete solution, so users who
149 run commands concurrently have to live with some risk of corruption (which
150 seems to be low in practice).
155 The 'git gc --auto' command will run the 'pre-auto-gc' hook. See
156 linkgit:githooks[5] for more information.
162 linkgit:git-reflog[1]
163 linkgit:git-repack[1]
164 linkgit:git-rerere[1]
168 Part of the linkgit:git[1] suite