1GIT-GC(1)                         Git Manual                         GIT-GC(1)
2
3
4

NAME

6       git-gc - Cleanup unnecessary files and optimize the local repository
7

SYNOPSIS

9       git gc [--aggressive] [--auto] [--quiet] [--prune=<date> | --no-prune] [--force] [--keep-largest-pack]
10

DESCRIPTION

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

OPTIONS

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       --[no-]cruft
51           When expiring unreachable objects, pack them separately into a
52           cruft pack instead of storing them as loose objects.  --cruft is on
53           by default.
54
55       --max-cruft-size=<n>
56           When packing unreachable objects into a cruft pack, limit the size
57           of new cruft packs to be at most <n> bytes. Overrides any value
58           specified via the gc.maxCruftSize configuration. See the
59           --max-cruft-size option of git-repack(1) for more.
60
61       --prune=<date>
62           Prune loose objects older than date (default is 2 weeks ago,
63           overridable by the config variable gc.pruneExpire). --prune=now
64           prunes loose objects regardless of their age and increases the risk
65           of corruption if another process is writing to the repository
66           concurrently; see "NOTES" below. --prune is on by default.
67
68       --no-prune
69           Do not prune any loose objects.
70
71       --quiet
72           Suppress all progress reports.
73
74       --force
75           Force git gc to run even if there may be another git gc instance
76           running on this repository.
77
78       --keep-largest-pack
79           All packs except the largest non-cruft pack, any packs marked with
80           a .keep file, and any cruft pack(s) are consolidated into a single
81           pack. When this option is used, gc.bigPackThreshold is ignored.
82

AGGRESSIVE

84       When the --aggressive option is supplied, git-repack(1) will be invoked
85       with the -f flag, which in turn will pass --no-reuse-delta to git-pack-
86       objects(1). This will throw away any existing deltas and re-compute
87       them, at the expense of spending much more time on the repacking.
88
89       The effects of this are mostly persistent, e.g. when packs and loose
90       objects are coalesced into one another pack the existing deltas in that
91       pack might get re-used, but there are also various cases where we might
92       pick a sub-optimal delta from a newer pack instead.
93
94       Furthermore, supplying --aggressive will tweak the --depth and --window
95       options passed to git-repack(1). See the gc.aggressiveDepth and
96       gc.aggressiveWindow settings below. By using a larger window size we’re
97       more likely to find more optimal deltas.
98
99       It’s probably not worth it to use this option on a given repository
100       without running tailored performance benchmarks on it. It takes a lot
101       more time, and the resulting space/delta optimization may or may not be
102       worth it. Not using this at all is the right trade-off for most users
103       and their repositories.
104

CONFIGURATION

106       Everything below this line in this section is selectively included from
107       the git-config(1) documentation. The content is the same as what’s
108       found there:
109
110       gc.aggressiveDepth
111           The depth parameter used in the delta compression algorithm used by
112           git gc --aggressive. This defaults to 50, which is the default for
113           the --depth option when --aggressive isn’t in use.
114
115           See the documentation for the --depth option in git-repack(1) for
116           more details.
117
118       gc.aggressiveWindow
119           The window size parameter used in the delta compression algorithm
120           used by git gc --aggressive. This defaults to 250, which is a much
121           more aggressive window size than the default --window of 10.
122
123           See the documentation for the --window option in git-repack(1) for
124           more details.
125
126       gc.auto
127           When there are approximately more than this many loose objects in
128           the repository, git gc --auto will pack them. Some Porcelain
129           commands use this command to perform a light-weight garbage
130           collection from time to time. The default value is 6700.
131
132           Setting this to 0 disables not only automatic packing based on the
133           number of loose objects, but also any other heuristic git gc --auto
134           will otherwise use to determine if there’s work to do, such as
135           gc.autoPackLimit.
136
137       gc.autoPackLimit
138           When there are more than this many packs that are not marked with
139           *.keep file in the repository, git gc --auto consolidates them into
140           one larger pack. The default value is 50. Setting this to 0
141           disables it. Setting gc.auto to 0 will also disable this.
142
143           See the gc.bigPackThreshold configuration variable below. When in
144           use, it’ll affect how the auto pack limit works.
145
146       gc.autoDetach
147           Make git gc --auto return immediately and run in the background if
148           the system supports it. Default is true.
149
150       gc.bigPackThreshold
151           If non-zero, all non-cruft packs larger than this limit are kept
152           when git gc is run. This is very similar to --keep-largest-pack
153           except that all non-cruft packs that meet the threshold are kept,
154           not just the largest pack. Defaults to zero. Common unit suffixes
155           of k, m, or g are supported.
156
157           Note that if the number of kept packs is more than
158           gc.autoPackLimit, this configuration variable is ignored, all packs
159           except the base pack will be repacked. After this the number of
160           packs should go below gc.autoPackLimit and gc.bigPackThreshold
161           should be respected again.
162
163           If the amount of memory estimated for git repack to run smoothly is
164           not available and gc.bigPackThreshold is not set, the largest pack
165           will also be excluded (this is the equivalent of running git gc
166           with --keep-largest-pack).
167
168       gc.writeCommitGraph
169           If true, then gc will rewrite the commit-graph file when git-gc(1)
170           is run. When using git gc --auto the commit-graph will be updated
171           if housekeeping is required. Default is true. See git-commit-
172           graph(1) for details.
173
174       gc.logExpiry
175           If the file gc.log exists, then git gc --auto will print its
176           content and exit with status zero instead of running unless that
177           file is more than gc.logExpiry old. Default is "1.day". See
178           gc.pruneExpire for more ways to specify its value.
179
180       gc.packRefs
181           Running git pack-refs in a repository renders it unclonable by Git
182           versions prior to 1.5.1.2 over dumb transports such as HTTP. This
183           variable determines whether git gc runs git pack-refs. This can be
184           set to notbare to enable it within all non-bare repos or it can be
185           set to a boolean value. The default is true.
186
187       gc.cruftPacks
188           Store unreachable objects in a cruft pack (see git-repack(1))
189           instead of as loose objects. The default is true.
190
191       gc.maxCruftSize
192           Limit the size of new cruft packs when repacking. When specified in
193           addition to --max-cruft-size, the command line option takes
194           priority. See the --max-cruft-size option of git-repack(1).
195
196       gc.pruneExpire
197           When git gc is run, it will call prune --expire 2.weeks.ago (and
198           repack --cruft --cruft-expiration 2.weeks.ago if using cruft packs
199           via gc.cruftPacks or --cruft). Override the grace period with this
200           config variable. The value "now" may be used to disable this grace
201           period and always prune unreachable objects immediately, or "never"
202           may be used to suppress pruning. This feature helps prevent
203           corruption when git gc runs concurrently with another process
204           writing to the repository; see the "NOTES" section of git-gc(1).
205
206       gc.worktreePruneExpire
207           When git gc is run, it calls git worktree prune --expire
208           3.months.ago. This config variable can be used to set a different
209           grace period. The value "now" may be used to disable the grace
210           period and prune $GIT_DIR/worktrees immediately, or "never" may be
211           used to suppress pruning.
212
213       gc.reflogExpire, gc.<pattern>.reflogExpire
214           git reflog expire removes reflog entries older than this time;
215           defaults to 90 days. The value "now" expires all entries
216           immediately, and "never" suppresses expiration altogether. With
217           "<pattern>" (e.g. "refs/stash") in the middle the setting applies
218           only to the refs that match the <pattern>.
219
220       gc.reflogExpireUnreachable, gc.<pattern>.reflogExpireUnreachable
221           git reflog expire removes reflog entries older than this time and
222           are not reachable from the current tip; defaults to 30 days. The
223           value "now" expires all entries immediately, and "never" suppresses
224           expiration altogether. With "<pattern>" (e.g. "refs/stash") in the
225           middle, the setting applies only to the refs that match the
226           <pattern>.
227
228           These types of entries are generally created as a result of using
229           git commit --amend or git rebase and are the commits prior to the
230           amend or rebase occurring. Since these changes are not part of the
231           current project most users will want to expire them sooner, which
232           is why the default is more aggressive than gc.reflogExpire.
233
234       gc.recentObjectsHook
235           When considering whether or not to remove an object (either when
236           generating a cruft pack or storing unreachable objects as loose),
237           use the shell to execute the specified command(s). Interpret their
238           output as object IDs which Git will consider as "recent",
239           regardless of their age. By treating their mtimes as "now", any
240           objects (and their descendants) mentioned in the output will be
241           kept regardless of their true age.
242
243           Output must contain exactly one hex object ID per line, and nothing
244           else. Objects which cannot be found in the repository are ignored.
245           Multiple hooks are supported, but all must exit successfully, else
246           the operation (either generating a cruft pack or unpacking
247           unreachable objects) will be halted.
248
249       gc.repackFilter
250           When repacking, use the specified filter to move certain objects
251           into a separate packfile. See the --filter=<filter-spec> option of
252           git-repack(1).
253
254       gc.repackFilterTo
255           When repacking and using a filter, see gc.repackFilter, the
256           specified location will be used to create the packfile containing
257           the filtered out objects.  WARNING: The specified location should
258           be accessible, using for example the Git alternates mechanism,
259           otherwise the repo could be considered corrupt by Git as it migh
260           not be able to access the objects in that packfile. See the
261           --filter-to=<dir> option of git-repack(1) and the
262           objects/info/alternates section of gitrepository-layout(5).
263
264       gc.rerereResolved
265           Records of conflicted merge you resolved earlier are kept for this
266           many days when git rerere gc is run. You can also use more
267           human-readable "1.month.ago", etc. The default is 60 days. See git-
268           rerere(1).
269
270       gc.rerereUnresolved
271           Records of conflicted merge you have not resolved are kept for this
272           many days when git rerere gc is run. You can also use more
273           human-readable "1.month.ago", etc. The default is 15 days. See git-
274           rerere(1).
275

NOTES

277       git gc tries very hard not to delete objects that are referenced
278       anywhere in your repository. In particular, it will keep not only
279       objects referenced by your current set of branches and tags, but also
280       objects referenced by the index, remote-tracking branches, reflogs
281       (which may reference commits in branches that were later amended or
282       rewound), and anything else in the refs/* namespace. Note that a note
283       (of the kind created by git notes) attached to an object does not
284       contribute in keeping the object alive. If you are expecting some
285       objects to be deleted and they aren’t, check all of those locations and
286       decide whether it makes sense in your case to remove those references.
287
288       On the other hand, when git gc runs concurrently with another process,
289       there is a risk of it deleting an object that the other process is
290       using but hasn’t created a reference to. This may just cause the other
291       process to fail or may corrupt the repository if the other process
292       later adds a reference to the deleted object. Git has two features that
293       significantly mitigate this problem:
294
295        1. Any object with modification time newer than the --prune date is
296           kept, along with everything reachable from it.
297
298        2. Most operations that add an object to the database update the
299           modification time of the object if it is already present so that #1
300           applies.
301
302       However, these features fall short of a complete solution, so users who
303       run commands concurrently have to live with some risk of corruption
304       (which seems to be low in practice).
305

HOOKS

307       The git gc --auto command will run the pre-auto-gc hook. See
308       githooks(5) for more information.
309

SEE ALSO

311       git-prune(1) git-reflog(1) git-repack(1) git-rerere(1)
312

GIT

314       Part of the git(1) suite
315
316
317
318Git 2.43.0                        11/20/2023                         GIT-GC(1)
Impressum