1GIT-MAINTENANCE(1) Git Manual GIT-MAINTENANCE(1)
2
3
4
6 git-maintenance - Run tasks to optimize Git repository data
7
9 git maintenance run [<options>]
10
12 Run tasks to optimize Git repository data, speeding up other Git
13 commands and reducing storage requirements for the repository.
14
15 Git commands that add repository data, such as git add or git fetch,
16 are optimized for a responsive user experience. These commands do not
17 take time to optimize the Git data, since such optimizations scale with
18 the full size of the repository while these user commands each perform
19 a relatively small action.
20
21 The git maintenance command provides flexibility for how to optimize
22 the Git repository.
23
25 register
26 Initialize Git config values so any scheduled maintenance will
27 start running on this repository. This adds the repository to the
28 maintenance.repo config variable in the current user’s global
29 config and enables some recommended configuration values for
30 maintenance.<task>.schedule. The tasks that are enabled are safe
31 for running in the background without disrupting foreground
32 processes.
33
34 The register subcommand will also set the maintenance.strategy
35 config value to incremental, if this value is not previously set.
36 The incremental strategy uses the following schedule for each
37 maintenance task:
38
39 · gc: disabled.
40
41 · commit-graph: hourly.
42
43 · prefetch: hourly.
44
45 · loose-objects: daily.
46
47 · incremental-repack: daily.
48
49 git maintenance register will also disable foreground maintenance
50 by setting maintenance.auto = false in the current repository. This
51 config setting will remain after a git maintenance unregister
52 command.
53
54 run
55 Run one or more maintenance tasks. If one or more --task options
56 are specified, then those tasks are run in that order. Otherwise,
57 the tasks are determined by which maintenance.<task>.enabled config
58 options are true. By default, only maintenance.gc.enabled is true.
59
60 start
61 Start running maintenance on the current repository. This performs
62 the same config updates as the register subcommand, then updates
63 the background scheduler to run git maintenance run --scheduled on
64 an hourly basis.
65
66 stop
67 Halt the background maintenance schedule. The current repository is
68 not removed from the list of maintained repositories, in case the
69 background maintenance is restarted later.
70
71 unregister
72 Remove the current repository from background maintenance. This
73 only removes the repository from the configured list. It does not
74 stop the background maintenance processes from running.
75
77 commit-graph
78 The commit-graph job updates the commit-graph files incrementally,
79 then verifies that the written data is correct. The incremental
80 write is safe to run alongside concurrent Git processes since it
81 will not expire .graph files that were in the previous
82 commit-graph-chain file. They will be deleted by a later run based
83 on the expiration delay.
84
85 prefetch
86 The prefetch task updates the object directory with the latest
87 objects from all registered remotes. For each remote, a git fetch
88 command is run. The refmap is custom to avoid updating local or
89 remote branches (those in refs/heads or refs/remotes). Instead, the
90 remote refs are stored in refs/prefetch/<remote>/. Also, tags are
91 not updated.
92
93 This is done to avoid disrupting the remote-tracking branches. The
94 end users expect these refs to stay unmoved unless they initiate a
95 fetch. With prefetch task, however, the objects necessary to
96 complete a later real fetch would already be obtained, so the real
97 fetch would go faster. In the ideal case, it will just become an
98 update to a bunch of remote-tracking branches without any object
99 transfer.
100
101 gc
102 Clean up unnecessary files and optimize the local repository. "GC"
103 stands for "garbage collection," but this task performs many
104 smaller tasks. This task can be expensive for large repositories,
105 as it repacks all Git objects into a single pack-file. It can also
106 be disruptive in some situations, as it deletes stale data. See
107 git-gc(1) for more details on garbage collection in Git.
108
109 loose-objects
110 The loose-objects job cleans up loose objects and places them into
111 pack-files. In order to prevent race conditions with concurrent Git
112 commands, it follows a two-step process. First, it deletes any
113 loose objects that already exist in a pack-file; concurrent Git
114 processes will examine the pack-file for the object data instead of
115 the loose object. Second, it creates a new pack-file (starting with
116 "loose-") containing a batch of loose objects. The batch size is
117 limited to 50 thousand objects to prevent the job from taking too
118 long on a repository with many loose objects. The gc task writes
119 unreachable objects as loose objects to be cleaned up by a later
120 step only if they are not re-added to a pack-file; for this reason
121 it is not advisable to enable both the loose-objects and gc tasks
122 at the same time.
123
124 incremental-repack
125 The incremental-repack job repacks the object directory using the
126 multi-pack-index feature. In order to prevent race conditions with
127 concurrent Git commands, it follows a two-step process. First, it
128 calls git multi-pack-index expire to delete pack-files unreferenced
129 by the multi-pack-index file. Second, it calls git multi-pack-index
130 repack to select several small pack-files and repack them into a
131 bigger one, and then update the multi-pack-index entries that refer
132 to the small pack-files to refer to the new pack-file. This
133 prepares those small pack-files for deletion upon the next run of
134 git multi-pack-index expire. The selection of the small pack-files
135 is such that the expected size of the big pack-file is at least the
136 batch size; see the --batch-size option for the repack subcommand
137 in git-multi-pack-index(1). The default batch-size is zero, which
138 is a special case that attempts to repack all pack-files into a
139 single pack-file.
140
142 --auto
143 When combined with the run subcommand, run maintenance tasks only
144 if certain thresholds are met. For example, the gc task runs when
145 the number of loose objects exceeds the number stored in the
146 gc.auto config setting, or when the number of pack-files exceeds
147 the gc.autoPackLimit config setting. Not compatible with the
148 --schedule option.
149
150 --schedule
151 When combined with the run subcommand, run maintenance tasks only
152 if certain time conditions are met, as specified by the
153 maintenance.<task>.schedule config value for each <task>. This
154 config value specifies a number of seconds since the last time that
155 task ran, according to the maintenance.<task>.lastRun config value.
156 The tasks that are tested are those provided by the --task=<task>
157 option(s) or those with maintenance.<task>.enabled set to true.
158
159 --quiet
160 Do not report progress or other information over stderr.
161
162 --task=<task>
163 If this option is specified one or more times, then only run the
164 specified tasks in the specified order. If no --task=<task>
165 arguments are specified, then only the tasks with
166 maintenance.<task>.enabled configured as true are considered. See
167 the TASKS section for the list of accepted <task> values.
168
170 The git maintenance command is designed to simplify the repository
171 maintenance patterns while minimizing user wait time during Git
172 commands. A variety of configuration options are available to allow
173 customizing this process. The default maintenance options focus on
174 operations that complete quickly, even on large repositories.
175
176 Users may find some cases where scheduled maintenance tasks do not run
177 as frequently as intended. Each git maintenance run command takes a
178 lock on the repository’s object database, and this prevents other
179 concurrent git maintenance run commands from running on the same
180 repository. Without this safeguard, competing processes could leave the
181 repository in an unpredictable state.
182
183 The background maintenance schedule runs git maintenance run processes
184 on an hourly basis. Each run executes the "hourly" tasks. At midnight,
185 that process also executes the "daily" tasks. At midnight on the first
186 day of the week, that process also executes the "weekly" tasks. A
187 single process iterates over each registered repository, performing the
188 scheduled tasks for that frequency. Depending on the number of
189 registered repositories and their sizes, this process may take longer
190 than an hour. In this case, multiple git maintenance run commands may
191 run on the same repository at the same time, colliding on the object
192 database lock. This results in one of the two tasks not running.
193
194 If you find that some maintenance windows are taking longer than one
195 hour to complete, then consider reducing the complexity of your
196 maintenance tasks. For example, the gc task is much slower than the
197 incremental-repack task. However, this comes at a cost of a slightly
198 larger object database. Consider moving more expensive tasks to be run
199 less frequently.
200
201 Expert users may consider scheduling their own maintenance tasks using
202 a different schedule than is available through git maintenance start
203 and Git configuration options. These users should be aware of the
204 object database lock and how concurrent git maintenance run commands
205 behave. Further, the git gc command should not be combined with git
206 maintenance run commands. git gc modifies the object database but does
207 not take the lock in the same way as git maintenance run. If possible,
208 use git maintenance run --task=gc instead of git gc.
209
211 Part of the git(1) suite
212
213
214
215Git 2.30.2 2021-03-08 GIT-MAINTENANCE(1)