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