1GIT-GC(1) Git Manual GIT-GC(1)
2
3
4
6 git-gc - Cleanup unnecessary files and optimize the local repository
7
9 git gc [--aggressive] [--auto] [--quiet] [--prune=<date> | --no-prune] [--force] [--keep-largest-pack]
10
12 Runs a number of housekeeping tasks within the current repository, such
13 as compressing file revisions (to reduce disk space and increase
14 performance), removing unreachable objects which may have been created
15 from prior invocations of git add, packing refs, pruning reflog, rerere
16 metadata or stale working trees. May also update ancillary indexes such
17 as the commit-graph.
18
19 When common porcelain operations that create objects are run, they will
20 check whether the repository has grown substantially since the last
21 maintenance, and if so run git gc automatically. See gc.auto below for
22 how to disable this behavior.
23
24 Running git gc manually should only be needed when adding objects to a
25 repository without regularly running such porcelain commands, to do a
26 one-off repository optimization, or e.g. to clean up a suboptimal
27 mass-import. See the "PACKFILE OPTIMIZATION" section in git-fast-
28 import(1) for more details on the import case.
29
31 --aggressive
32 Usually git gc runs very quickly while providing good disk space
33 utilization and performance. This option will cause git gc to more
34 aggressively optimize the repository at the expense of taking much
35 more time. The effects of this optimization are mostly persistent.
36 See the "AGGRESSIVE" section below for details.
37
38 --auto
39 With this option, git gc checks whether any housekeeping is
40 required; if not, it exits without performing any work.
41
42 See the gc.auto option in the "CONFIGURATION" section below for how
43 this heuristic works.
44
45 Once housekeeping is triggered by exceeding the limits of
46 configuration options such as gc.auto and gc.autoPackLimit, all
47 other housekeeping tasks (e.g. rerere, working trees, reflog...)
48 will be performed as well.
49
50 --prune=<date>
51 Prune loose objects older than date (default is 2 weeks ago,
52 overridable by the config variable gc.pruneExpire). --prune=now
53 prunes loose objects regardless of their age and increases the risk
54 of corruption if another process is writing to the repository
55 concurrently; see "NOTES" below. --prune is on by default.
56
57 --no-prune
58 Do not prune any loose objects.
59
60 --quiet
61 Suppress all progress reports.
62
63 --force
64 Force git gc to run even if there may be another git gc instance
65 running on this repository.
66
67 --keep-largest-pack
68 All packs except the largest pack and those marked with a .keep
69 files are consolidated into a single pack. When this option is
70 used, gc.bigPackThreshold is ignored.
71
73 When the --aggressive option is supplied, git-repack(1) will be invoked
74 with the -f flag, which in turn will pass --no-reuse-delta to git-pack-
75 objects(1). This will throw away any existing deltas and re-compute
76 them, at the expense of spending much more time on the repacking.
77
78 The effects of this are mostly persistent, e.g. when packs and loose
79 objects are coalesced into one another pack the existing deltas in that
80 pack might get re-used, but there are also various cases where we might
81 pick a sub-optimal delta from a newer pack instead.
82
83 Furthermore, supplying --aggressive will tweak the --depth and --window
84 options passed to git-repack(1). See the gc.aggressiveDepth and
85 gc.aggressiveWindow settings below. By using a larger window size we’re
86 more likely to find more optimal deltas.
87
88 It’s probably not worth it to use this option on a given repository
89 without running tailored performance benchmarks on it. It takes a lot
90 more time, and the resulting space/delta optimization may or may not be
91 worth it. Not using this at all is the right trade-off for most users
92 and their repositories.
93
95 The below documentation is the same as what’s found in git-config(1):
96
97 gc.aggressiveDepth
98 The depth parameter used in the delta compression algorithm used by
99 git gc --aggressive. This defaults to 50, which is the default for
100 the --depth option when --aggressive isn’t in use.
101
102 See the documentation for the --depth option in git-repack(1) for
103 more details.
104
105 gc.aggressiveWindow
106 The window size parameter used in the delta compression algorithm
107 used by git gc --aggressive. This defaults to 250, which is a much
108 more aggressive window size than the default --window of 10.
109
110 See the documentation for the --window option in git-repack(1) for
111 more details.
112
113 gc.auto
114 When there are approximately more than this many loose objects in
115 the repository, git gc --auto will pack them. Some Porcelain
116 commands use this command to perform a light-weight garbage
117 collection from time to time. The default value is 6700.
118
119 Setting this to 0 disables not only automatic packing based on the
120 number of loose objects, but any other heuristic git gc --auto will
121 otherwise use to determine if there’s work to do, such as
122 gc.autoPackLimit.
123
124 gc.autoPackLimit
125 When there are more than this many packs that are not marked with
126 *.keep file in the repository, git gc --auto consolidates them into
127 one larger pack. The default value is 50. Setting this to 0
128 disables it. Setting gc.auto to 0 will also disable this.
129
130 See the gc.bigPackThreshold configuration variable below. When in
131 use, it’ll affect how the auto pack limit works.
132
133 gc.autoDetach
134 Make git gc --auto return immediately and run in background if the
135 system supports it. Default is true.
136
137 gc.bigPackThreshold
138 If non-zero, all packs larger than this limit are kept when git gc
139 is run. This is very similar to --keep-largest-pack except that all
140 packs that meet the threshold are kept, not just the largest pack.
141 Defaults to zero. Common unit suffixes of k, m, or g are supported.
142
143 Note that if the number of kept packs is more than
144 gc.autoPackLimit, this configuration variable is ignored, all packs
145 except the base pack will be repacked. After this the number of
146 packs should go below gc.autoPackLimit and gc.bigPackThreshold
147 should be respected again.
148
149 If the amount of memory estimated for git repack to run smoothly is
150 not available and gc.bigPackThreshold is not set, the largest pack
151 will also be excluded (this is the equivalent of running git gc
152 with --keep-largest-pack).
153
154 gc.writeCommitGraph
155 If true, then gc will rewrite the commit-graph file when git-gc(1)
156 is run. When using git gc --auto the commit-graph will be updated
157 if housekeeping is required. Default is true. See git-commit-
158 graph(1) for details.
159
160 gc.logExpiry
161 If the file gc.log exists, then git gc --auto will print its
162 content and exit with status zero instead of running unless that
163 file is more than gc.logExpiry old. Default is "1.day". See
164 gc.pruneExpire for more ways to specify its value.
165
166 gc.packRefs
167 Running git pack-refs in a repository renders it unclonable by Git
168 versions prior to 1.5.1.2 over dumb transports such as HTTP. This
169 variable determines whether git gc runs git pack-refs. This can be
170 set to notbare to enable it within all non-bare repos or it can be
171 set to a boolean value. The default is true.
172
173 gc.pruneExpire
174 When git gc is run, it will call prune --expire 2.weeks.ago.
175 Override the grace period with this config variable. The value
176 "now" may be used to disable this grace period and always prune
177 unreachable objects immediately, or "never" may be used to suppress
178 pruning. This feature helps prevent corruption when git gc runs
179 concurrently with another process writing to the repository; see
180 the "NOTES" section of git-gc(1).
181
182 gc.worktreePruneExpire
183 When git gc is run, it calls git worktree prune --expire
184 3.months.ago. This config variable can be used to set a different
185 grace period. The value "now" may be used to disable the grace
186 period and prune $GIT_DIR/worktrees immediately, or "never" may be
187 used to suppress pruning.
188
189 gc.reflogExpire, gc.<pattern>.reflogExpire
190 git reflog expire removes reflog entries older than this time;
191 defaults to 90 days. The value "now" expires all entries
192 immediately, and "never" suppresses expiration altogether. With
193 "<pattern>" (e.g. "refs/stash") in the middle the setting applies
194 only to the refs that match the <pattern>.
195
196 gc.reflogExpireUnreachable, gc.<pattern>.reflogExpireUnreachable
197 git reflog expire removes reflog entries older than this time and
198 are not reachable from the current tip; defaults to 30 days. The
199 value "now" expires all entries immediately, and "never" suppresses
200 expiration altogether. With "<pattern>" (e.g. "refs/stash") in the
201 middle, the setting applies only to the refs that match the
202 <pattern>.
203
204 These types of entries are generally created as a result of using
205 git commit --amend or git rebase and are the commits prior to the
206 amend or rebase occurring. Since these changes are not part of the
207 current project most users will want to expire them sooner, which
208 is why the default is more aggressive than gc.reflogExpire.
209
210 gc.rerereResolved
211 Records of conflicted merge you resolved earlier are kept for this
212 many days when git rerere gc is run. You can also use more
213 human-readable "1.month.ago", etc. The default is 60 days. See git-
214 rerere(1).
215
216 gc.rerereUnresolved
217 Records of conflicted merge you have not resolved are kept for this
218 many days when git rerere gc is run. You can also use more
219 human-readable "1.month.ago", etc. The default is 15 days. See git-
220 rerere(1).
221
223 git gc tries very hard not to delete objects that are referenced
224 anywhere in your repository. In particular, it will keep not only
225 objects referenced by your current set of branches and tags, but also
226 objects referenced by the index, remote-tracking branches, notes saved
227 by git notes under refs/notes/, reflogs (which may reference commits in
228 branches that were later amended or rewound), and anything else in the
229 refs/* namespace. If you are expecting some objects to be deleted and
230 they aren’t, check all of those locations and decide whether it makes
231 sense in your case to remove those references.
232
233 On the other hand, when git gc runs concurrently with another process,
234 there is a risk of it deleting an object that the other process is
235 using but hasn’t created a reference to. This may just cause the other
236 process to fail or may corrupt the repository if the other process
237 later adds a reference to the deleted object. Git has two features that
238 significantly mitigate this problem:
239
240 1. Any object with modification time newer than the --prune date is
241 kept, along with everything reachable from it.
242
243 2. Most operations that add an object to the database update the
244 modification time of the object if it is already present so that #1
245 applies.
246
247 However, these features fall short of a complete solution, so users who
248 run commands concurrently have to live with some risk of corruption
249 (which seems to be low in practice).
250
252 The git gc --auto command will run the pre-auto-gc hook. See
253 githooks(5) for more information.
254
256 git-prune(1) git-reflog(1) git-repack(1) git-rerere(1)
257
259 Part of the git(1) suite
260
261
262
263Git 2.30.2 2021-03-08 GIT-GC(1)