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
11
13 Runs a number of housekeeping tasks within the current repository, such
14 as compressing file revisions (to reduce disk space and increase
15 performance), removing unreachable objects which may have been created
16 from prior invocations of git add, packing refs, pruning reflog, rerere
17 metadata or stale working trees. May also update ancillary indexes such
18 as the commit-graph.
19
20 Users are encouraged to run this task on a regular basis within each
21 repository to maintain good disk space utilization and good operating
22 performance.
23
24 Some git commands may automatically run git gc; see the --auto flag
25 below for details. If you know what you’re doing and all you want is to
26 disable this behavior permanently without further considerations, just
27 do:
28
29 $ git config --global gc.auto 0
30
31
33 --aggressive
34 Usually git gc runs very quickly while providing good disk space
35 utilization and performance. This option will cause git gc to more
36 aggressively optimize the repository at the expense of taking much
37 more time. The effects of this optimization are persistent, so this
38 option only needs to be used occasionally; every few hundred
39 changesets or so.
40
41 --auto
42 With this option, git gc checks whether any housekeeping is
43 required; if not, it exits without performing any work. Some git
44 commands run git gc --auto after performing operations that could
45 create many loose objects. Housekeeping is required if there are
46 too many loose objects or too many packs in the repository.
47
48 If the number of loose objects exceeds the value of the gc.auto
49 configuration variable, then all loose objects are combined into a
50 single pack using git repack -d -l. Setting the value of gc.auto to
51 0 disables automatic packing of loose objects.
52
53 If the number of packs exceeds the value of gc.autoPackLimit, then
54 existing packs (except those marked with a .keep file or over
55 gc.bigPackThreshold limit) are consolidated into a single pack by
56 using the -A option of git repack. If the amount of memory is
57 estimated not enough for git repack to run smoothly and
58 gc.bigPackThreshold is not set, the largest pack will also be
59 excluded (this is the equivalent of running git gc with
60 --keep-base-pack). Setting gc.autoPackLimit to 0 disables automatic
61 consolidation of packs.
62
63 If houskeeping is required due to many loose objects or packs, all
64 other housekeeping tasks (e.g. rerere, working trees, reflog...)
65 will be performed as well.
66
67 --prune=<date>
68 Prune loose objects older than date (default is 2 weeks ago,
69 overridable by the config variable gc.pruneExpire). --prune=all
70 prunes loose objects regardless of their age and increases the risk
71 of corruption if another process is writing to the repository
72 concurrently; see "NOTES" below. --prune is on by default.
73
74 --no-prune
75 Do not prune any loose objects.
76
77 --quiet
78 Suppress all progress reports.
79
80 --force
81 Force git gc to run even if there may be another git gc instance
82 running on this repository.
83
84 --keep-largest-pack
85 All packs except the largest pack and those marked with a .keep
86 files are consolidated into a single pack. When this option is
87 used, gc.bigPackThreshold is ignored.
88
90 The optional configuration variable gc.reflogExpire can be set to
91 indicate how long historical entries within each branch’s reflog should
92 remain available in this repository. The setting is expressed as a
93 length of time, for example 90 days or 3 months. It defaults to 90
94 days.
95
96 The optional configuration variable gc.reflogExpireUnreachable can be
97 set to indicate how long historical reflog entries which are not part
98 of the current branch should remain available in this repository. These
99 types of entries are generally created as a result of using git commit
100 --amend or git rebase and are the commits prior to the amend or rebase
101 occurring. Since these changes are not part of the current project most
102 users will want to expire them sooner. This option defaults to 30 days.
103
104 The above two configuration variables can be given to a pattern. For
105 example, this sets non-default expiry values only to remote-tracking
106 branches:
107
108 [gc "refs/remotes/*"]
109 reflogExpire = never
110 reflogExpireUnreachable = 3 days
111
112
113 The optional configuration variable gc.rerereResolved indicates how
114 long records of conflicted merge you resolved earlier are kept. This
115 defaults to 60 days.
116
117 The optional configuration variable gc.rerereUnresolved indicates how
118 long records of conflicted merge you have not resolved are kept. This
119 defaults to 15 days.
120
121 The optional configuration variable gc.packRefs determines if git gc
122 runs git pack-refs. This can be set to "notbare" to enable it within
123 all non-bare repos or it can be set to a boolean value. This defaults
124 to true.
125
126 The optional configuration variable gc.commitGraph determines if git gc
127 should run git commit-graph write. This can be set to a boolean value.
128 This defaults to false.
129
130 The optional configuration variable gc.aggressiveWindow controls how
131 much time is spent optimizing the delta compression of the objects in
132 the repository when the --aggressive option is specified. The larger
133 the value, the more time is spent optimizing the delta compression. See
134 the documentation for the --window option in git-repack(1) for more
135 details. This defaults to 250.
136
137 Similarly, the optional configuration variable gc.aggressiveDepth
138 controls --depth option in git-repack(1). This defaults to 50.
139
140 The optional configuration variable gc.pruneExpire controls how old the
141 unreferenced loose objects have to be before they are pruned. The
142 default is "2 weeks ago".
143
144 Optional configuration variable gc.worktreePruneExpire controls how old
145 a stale working tree should be before git worktree prune deletes it.
146 Default is "3 months ago".
147
149 git gc tries very hard not to delete objects that are referenced
150 anywhere in your repository. In particular, it will keep not only
151 objects referenced by your current set of branches and tags, but also
152 objects referenced by the index, remote-tracking branches, refs saved
153 by git filter-branch in refs/original/, or reflogs (which may reference
154 commits in branches that were later amended or rewound). If you are
155 expecting some objects to be deleted and they aren’t, check all of
156 those locations and decide whether it makes sense in your case to
157 remove those references.
158
159 On the other hand, when git gc runs concurrently with another process,
160 there is a risk of it deleting an object that the other process is
161 using but hasn’t created a reference to. This may just cause the other
162 process to fail or may corrupt the repository if the other process
163 later adds a reference to the deleted object. Git has two features that
164 significantly mitigate this problem:
165
166 1. Any object with modification time newer than the --prune date is
167 kept, along with everything reachable from it.
168
169 2. Most operations that add an object to the database update the
170 modification time of the object if it is already present so that #1
171 applies.
172
173 However, these features fall short of a complete solution, so users who
174 run commands concurrently have to live with some risk of corruption
175 (which seems to be low in practice) unless they turn off automatic
176 garbage collection with git config gc.auto 0.
177
179 The git gc --auto command will run the pre-auto-gc hook. See
180 githooks(5) for more information.
181
183 git-prune(1) git-reflog(1) git-repack(1) git-rerere(1)
184
186 Part of the git(1) suite
187
188
189
190Git 2.20.1 12/15/2018 GIT-GC(1)