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       --cruft
51           When expiring unreachable objects, pack them separately into a
52           cruft pack instead of storing them as loose objects.
53
54       --prune=<date>
55           Prune loose objects older than date (default is 2 weeks ago,
56           overridable by the config variable gc.pruneExpire). --prune=now
57           prunes loose objects regardless of their age and increases the risk
58           of corruption if another process is writing to the repository
59           concurrently; see "NOTES" below. --prune is on by default.
60
61       --no-prune
62           Do not prune any loose objects.
63
64       --quiet
65           Suppress all progress reports.
66
67       --force
68           Force git gc to run even if there may be another git gc instance
69           running on this repository.
70
71       --keep-largest-pack
72           All packs except the largest pack and those marked with a .keep
73           files are consolidated into a single pack. When this option is
74           used, gc.bigPackThreshold is ignored.
75

AGGRESSIVE

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

CONFIGURATION

99       Everything below this line in this section is selectively included from
100       the git-config(1) documentation. The content is the same as what’s
101       found there:
102
103       gc.aggressiveDepth
104           The depth parameter used in the delta compression algorithm used by
105           git gc --aggressive. This defaults to 50, which is the default for
106           the --depth option when --aggressive isn’t in use.
107
108           See the documentation for the --depth option in git-repack(1) for
109           more details.
110
111       gc.aggressiveWindow
112           The window size parameter used in the delta compression algorithm
113           used by git gc --aggressive. This defaults to 250, which is a much
114           more aggressive window size than the default --window of 10.
115
116           See the documentation for the --window option in git-repack(1) for
117           more details.
118
119       gc.auto
120           When there are approximately more than this many loose objects in
121           the repository, git gc --auto will pack them. Some Porcelain
122           commands use this command to perform a light-weight garbage
123           collection from time to time. The default value is 6700.
124
125           Setting this to 0 disables not only automatic packing based on the
126           number of loose objects, but any other heuristic git gc --auto will
127           otherwise use to determine if there’s work to do, such as
128           gc.autoPackLimit.
129
130       gc.autoPackLimit
131           When there are more than this many packs that are not marked with
132           *.keep file in the repository, git gc --auto consolidates them into
133           one larger pack. The default value is 50. Setting this to 0
134           disables it. Setting gc.auto to 0 will also disable this.
135
136           See the gc.bigPackThreshold configuration variable below. When in
137           use, it’ll affect how the auto pack limit works.
138
139       gc.autoDetach
140           Make git gc --auto return immediately and run in background if the
141           system supports it. Default is true.
142
143       gc.bigPackThreshold
144           If non-zero, all packs larger than this limit are kept when git gc
145           is run. This is very similar to --keep-largest-pack except that all
146           packs that meet the threshold are kept, not just the largest pack.
147           Defaults to zero. Common unit suffixes of k, m, or g are supported.
148
149           Note that if the number of kept packs is more than
150           gc.autoPackLimit, this configuration variable is ignored, all packs
151           except the base pack will be repacked. After this the number of
152           packs should go below gc.autoPackLimit and gc.bigPackThreshold
153           should be respected again.
154
155           If the amount of memory estimated for git repack to run smoothly is
156           not available and gc.bigPackThreshold is not set, the largest pack
157           will also be excluded (this is the equivalent of running git gc
158           with --keep-largest-pack).
159
160       gc.writeCommitGraph
161           If true, then gc will rewrite the commit-graph file when git-gc(1)
162           is run. When using git gc --auto the commit-graph will be updated
163           if housekeeping is required. Default is true. See git-commit-
164           graph(1) for details.
165
166       gc.logExpiry
167           If the file gc.log exists, then git gc --auto will print its
168           content and exit with status zero instead of running unless that
169           file is more than gc.logExpiry old. Default is "1.day". See
170           gc.pruneExpire for more ways to specify its value.
171
172       gc.packRefs
173           Running git pack-refs in a repository renders it unclonable by Git
174           versions prior to 1.5.1.2 over dumb transports such as HTTP. This
175           variable determines whether git gc runs git pack-refs. This can be
176           set to notbare to enable it within all non-bare repos or it can be
177           set to a boolean value. The default is true.
178
179       gc.cruftPacks
180           Store unreachable objects in a cruft pack (see git-repack(1))
181           instead of as loose objects. The default is false.
182
183       gc.pruneExpire
184           When git gc is run, it will call prune --expire 2.weeks.ago (and
185           repack --cruft --cruft-expiration 2.weeks.ago if using cruft packs
186           via gc.cruftPacks or --cruft). Override the grace period with this
187           config variable. The value "now" may be used to disable this grace
188           period and always prune unreachable objects immediately, or "never"
189           may be used to suppress pruning. This feature helps prevent
190           corruption when git gc runs concurrently with another process
191           writing to the repository; see the "NOTES" section of git-gc(1).
192
193       gc.worktreePruneExpire
194           When git gc is run, it calls git worktree prune --expire
195           3.months.ago. This config variable can be used to set a different
196           grace period. The value "now" may be used to disable the grace
197           period and prune $GIT_DIR/worktrees immediately, or "never" may be
198           used to suppress pruning.
199
200       gc.reflogExpire, gc.<pattern>.reflogExpire
201           git reflog expire removes reflog entries older than this time;
202           defaults to 90 days. The value "now" expires all entries
203           immediately, and "never" suppresses expiration altogether. With
204           "<pattern>" (e.g. "refs/stash") in the middle the setting applies
205           only to the refs that match the <pattern>.
206
207       gc.reflogExpireUnreachable, gc.<pattern>.reflogExpireUnreachable
208           git reflog expire removes reflog entries older than this time and
209           are not reachable from the current tip; defaults to 30 days. The
210           value "now" expires all entries immediately, and "never" suppresses
211           expiration altogether. With "<pattern>" (e.g. "refs/stash") in the
212           middle, the setting applies only to the refs that match the
213           <pattern>.
214
215           These types of entries are generally created as a result of using
216           git commit --amend or git rebase and are the commits prior to the
217           amend or rebase occurring. Since these changes are not part of the
218           current project most users will want to expire them sooner, which
219           is why the default is more aggressive than gc.reflogExpire.
220
221       gc.rerereResolved
222           Records of conflicted merge you resolved earlier are kept for this
223           many days when git rerere gc is run. You can also use more
224           human-readable "1.month.ago", etc. The default is 60 days. See git-
225           rerere(1).
226
227       gc.rerereUnresolved
228           Records of conflicted merge you have not resolved are kept for this
229           many days when git rerere gc is run. You can also use more
230           human-readable "1.month.ago", etc. The default is 15 days. See git-
231           rerere(1).
232

NOTES

234       git gc tries very hard not to delete objects that are referenced
235       anywhere in your repository. In particular, it will keep not only
236       objects referenced by your current set of branches and tags, but also
237       objects referenced by the index, remote-tracking branches, reflogs
238       (which may reference commits in branches that were later amended or
239       rewound), and anything else in the refs/* namespace. Note that a note
240       (of the kind created by git notes) attached to an object does not
241       contribute in keeping the object alive. If you are expecting some
242       objects to be deleted and they aren’t, check all of those locations and
243       decide whether it makes sense in your case to remove those references.
244
245       On the other hand, when git gc runs concurrently with another process,
246       there is a risk of it deleting an object that the other process is
247       using but hasn’t created a reference to. This may just cause the other
248       process to fail or may corrupt the repository if the other process
249       later adds a reference to the deleted object. Git has two features that
250       significantly mitigate this problem:
251
252        1. Any object with modification time newer than the --prune date is
253           kept, along with everything reachable from it.
254
255        2. Most operations that add an object to the database update the
256           modification time of the object if it is already present so that #1
257           applies.
258
259       However, these features fall short of a complete solution, so users who
260       run commands concurrently have to live with some risk of corruption
261       (which seems to be low in practice).
262

HOOKS

264       The git gc --auto command will run the pre-auto-gc hook. See
265       githooks(5) for more information.
266

SEE ALSO

268       git-prune(1) git-reflog(1) git-repack(1) git-rerere(1)
269

GIT

271       Part of the git(1) suite
272
273
274
275Git 2.39.1                        2023-01-13                         GIT-GC(1)
Impressum