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

NAME

6       git-maintenance - Run tasks to optimize Git repository data
7

SYNOPSIS

9       git maintenance run [<options>]
10       git maintenance start [--scheduler=<scheduler>]
11       git maintenance (stop|register|unregister) [<options>]
12

DESCRIPTION

14       Run tasks to optimize Git repository data, speeding up other Git
15       commands and reducing storage requirements for the repository.
16
17       Git commands that add repository data, such as git add or git fetch,
18       are optimized for a responsive user experience. These commands do not
19       take time to optimize the Git data, since such optimizations scale with
20       the full size of the repository while these user commands each perform
21       a relatively small action.
22
23       The git maintenance command provides flexibility for how to optimize
24       the Git repository.
25

SUBCOMMANDS

27       run
28           Run one or more maintenance tasks. If one or more --task options
29           are specified, then those tasks are run in that order. Otherwise,
30           the tasks are determined by which maintenance.<task>.enabled config
31           options are true. By default, only maintenance.gc.enabled is true.
32
33       start
34           Start running maintenance on the current repository. This performs
35           the same config updates as the register subcommand, then updates
36           the background scheduler to run git maintenance run --scheduled on
37           an hourly basis.
38
39       stop
40           Halt the background maintenance schedule. The current repository is
41           not removed from the list of maintained repositories, in case the
42           background maintenance is restarted later.
43
44       register
45           Initialize Git config values so any scheduled maintenance will
46           start running on this repository. This adds the repository to the
47           maintenance.repo config variable in the current user’s global
48           config, or the config specified by --config-file option, and
49           enables some recommended configuration values for
50           maintenance.<task>.schedule. The tasks that are enabled are safe
51           for running in the background without disrupting foreground
52           processes.
53
54           The register subcommand will also set the maintenance.strategy
55           config value to incremental, if this value is not previously set.
56           The incremental strategy uses the following schedule for each
57           maintenance task:
58
59gc: disabled.
60
61commit-graph: hourly.
62
63prefetch: hourly.
64
65loose-objects: daily.
66
67incremental-repack: daily.
68
69           git maintenance register will also disable foreground maintenance
70           by setting maintenance.auto = false in the current repository. This
71           config setting will remain after a git maintenance unregister
72           command.
73
74       unregister
75           Remove the current repository from background maintenance. This
76           only removes the repository from the configured list. It does not
77           stop the background maintenance processes from running.
78
79           The unregister subcommand will report an error if the current
80           repository is not already registered. Use the --force option to
81           return success even when the current repository is not registered.
82

TASKS

84       commit-graph
85           The commit-graph job updates the commit-graph files incrementally,
86           then verifies that the written data is correct. The incremental
87           write is safe to run alongside concurrent Git processes since it
88           will not expire .graph files that were in the previous
89           commit-graph-chain file. They will be deleted by a later run based
90           on the expiration delay.
91
92       prefetch
93           The prefetch task updates the object directory with the latest
94           objects from all registered remotes. For each remote, a git fetch
95           command is run. The configured refspec is modified to place all
96           requested refs within refs/prefetch/. Also, tags are not updated.
97
98           This is done to avoid disrupting the remote-tracking branches. The
99           end users expect these refs to stay unmoved unless they initiate a
100           fetch. With prefetch task, however, the objects necessary to
101           complete a later real fetch would already be obtained, so the real
102           fetch would go faster. In the ideal case, it will just become an
103           update to a bunch of remote-tracking branches without any object
104           transfer.
105
106       gc
107           Clean up unnecessary files and optimize the local repository. "GC"
108           stands for "garbage collection," but this task performs many
109           smaller tasks. This task can be expensive for large repositories,
110           as it repacks all Git objects into a single pack-file. It can also
111           be disruptive in some situations, as it deletes stale data. See
112           git-gc(1) for more details on garbage collection in Git.
113
114       loose-objects
115           The loose-objects job cleans up loose objects and places them into
116           pack-files. In order to prevent race conditions with concurrent Git
117           commands, it follows a two-step process. First, it deletes any
118           loose objects that already exist in a pack-file; concurrent Git
119           processes will examine the pack-file for the object data instead of
120           the loose object. Second, it creates a new pack-file (starting with
121           "loose-") containing a batch of loose objects. The batch size is
122           limited to 50 thousand objects to prevent the job from taking too
123           long on a repository with many loose objects. The gc task writes
124           unreachable objects as loose objects to be cleaned up by a later
125           step only if they are not re-added to a pack-file; for this reason
126           it is not advisable to enable both the loose-objects and gc tasks
127           at the same time.
128
129       incremental-repack
130           The incremental-repack job repacks the object directory using the
131           multi-pack-index feature. In order to prevent race conditions with
132           concurrent Git commands, it follows a two-step process. First, it
133           calls git multi-pack-index expire to delete pack-files unreferenced
134           by the multi-pack-index file. Second, it calls git multi-pack-index
135           repack to select several small pack-files and repack them into a
136           bigger one, and then update the multi-pack-index entries that refer
137           to the small pack-files to refer to the new pack-file. This
138           prepares those small pack-files for deletion upon the next run of
139           git multi-pack-index expire. The selection of the small pack-files
140           is such that the expected size of the big pack-file is at least the
141           batch size; see the --batch-size option for the repack subcommand
142           in git-multi-pack-index(1). The default batch-size is zero, which
143           is a special case that attempts to repack all pack-files into a
144           single pack-file.
145
146       pack-refs
147           The pack-refs task collects the loose reference files and collects
148           them into a single file. This speeds up operations that need to
149           iterate across many references. See git-pack-refs(1) for more
150           information.
151

OPTIONS

153       --auto
154           When combined with the run subcommand, run maintenance tasks only
155           if certain thresholds are met. For example, the gc task runs when
156           the number of loose objects exceeds the number stored in the
157           gc.auto config setting, or when the number of pack-files exceeds
158           the gc.autoPackLimit config setting. Not compatible with the
159           --schedule option.
160
161       --schedule
162           When combined with the run subcommand, run maintenance tasks only
163           if certain time conditions are met, as specified by the
164           maintenance.<task>.schedule config value for each <task>. This
165           config value specifies a number of seconds since the last time that
166           task ran, according to the maintenance.<task>.lastRun config value.
167           The tasks that are tested are those provided by the --task=<task>
168           option(s) or those with maintenance.<task>.enabled set to true.
169
170       --quiet
171           Do not report progress or other information over stderr.
172
173       --task=<task>
174           If this option is specified one or more times, then only run the
175           specified tasks in the specified order. If no --task=<task>
176           arguments are specified, then only the tasks with
177           maintenance.<task>.enabled configured as true are considered. See
178           the TASKS section for the list of accepted <task> values.
179
180       --scheduler=auto|crontab|systemd-timer|launchctl|schtasks
181           When combined with the start subcommand, specify the scheduler for
182           running the hourly, daily and weekly executions of git maintenance
183           run. Possible values for <scheduler> are auto, crontab (POSIX),
184           systemd-timer (Linux), launchctl (macOS), and schtasks (Windows).
185           When auto is specified, the appropriate platform-specific scheduler
186           is used; on Linux, systemd-timer is used if available, otherwise
187           crontab. Default is auto.
188

TROUBLESHOOTING

190       The git maintenance command is designed to simplify the repository
191       maintenance patterns while minimizing user wait time during Git
192       commands. A variety of configuration options are available to allow
193       customizing this process. The default maintenance options focus on
194       operations that complete quickly, even on large repositories.
195
196       Users may find some cases where scheduled maintenance tasks do not run
197       as frequently as intended. Each git maintenance run command takes a
198       lock on the repository’s object database, and this prevents other
199       concurrent git maintenance run commands from running on the same
200       repository. Without this safeguard, competing processes could leave the
201       repository in an unpredictable state.
202
203       The background maintenance schedule runs git maintenance run processes
204       on an hourly basis. Each run executes the "hourly" tasks. At midnight,
205       that process also executes the "daily" tasks. At midnight on the first
206       day of the week, that process also executes the "weekly" tasks. A
207       single process iterates over each registered repository, performing the
208       scheduled tasks for that frequency. Depending on the number of
209       registered repositories and their sizes, this process may take longer
210       than an hour. In this case, multiple git maintenance run commands may
211       run on the same repository at the same time, colliding on the object
212       database lock. This results in one of the two tasks not running.
213
214       If you find that some maintenance windows are taking longer than one
215       hour to complete, then consider reducing the complexity of your
216       maintenance tasks. For example, the gc task is much slower than the
217       incremental-repack task. However, this comes at a cost of a slightly
218       larger object database. Consider moving more expensive tasks to be run
219       less frequently.
220
221       Expert users may consider scheduling their own maintenance tasks using
222       a different schedule than is available through git maintenance start
223       and Git configuration options. These users should be aware of the
224       object database lock and how concurrent git maintenance run commands
225       behave. Further, the git gc command should not be combined with git
226       maintenance run commands. git gc modifies the object database but does
227       not take the lock in the same way as git maintenance run. If possible,
228       use git maintenance run --task=gc instead of git gc.
229
230       The following sections describe the mechanisms put in place to run
231       background maintenance by git maintenance start and how to customize
232       them.
233

BACKGROUND MAINTENANCE ON POSIX SYSTEMS

235       The standard mechanism for scheduling background tasks on POSIX systems
236       is cron(8). This tool executes commands based on a given schedule. The
237       current list of user-scheduled tasks can be found by running crontab
238       -l. The schedule written by git maintenance start is similar to this:
239
240           # BEGIN GIT MAINTENANCE SCHEDULE
241           # The following schedule was created by Git
242           # Any edits made in this region might be
243           # replaced in the future by a Git command.
244
245           0 1-23 * * * "/<path>/git" --exec-path="/<path>" for-each-repo --config=maintenance.repo maintenance run --schedule=hourly
246           0 0 * * 1-6 "/<path>/git" --exec-path="/<path>" for-each-repo --config=maintenance.repo maintenance run --schedule=daily
247           0 0 * * 0 "/<path>/git" --exec-path="/<path>" for-each-repo --config=maintenance.repo maintenance run --schedule=weekly
248
249           # END GIT MAINTENANCE SCHEDULE
250
251       The comments are used as a region to mark the schedule as written by
252       Git. Any modifications within this region will be completely deleted by
253       git maintenance stop or overwritten by git maintenance start.
254
255       The crontab entry specifies the full path of the git executable to
256       ensure that the executed git command is the same one with which git
257       maintenance start was issued independent of PATH. If the same user runs
258       git maintenance start with multiple Git executables, then only the
259       latest executable is used.
260
261       These commands use git for-each-repo --config=maintenance.repo to run
262       git maintenance run --schedule=<frequency> on each repository listed in
263       the multi-valued maintenance.repo config option. These are typically
264       loaded from the user-specific global config. The git maintenance
265       process then determines which maintenance tasks are configured to run
266       on each repository with each <frequency> using the
267       maintenance.<task>.schedule config options. These values are loaded
268       from the global or repository config values.
269
270       If the config values are insufficient to achieve your desired
271       background maintenance schedule, then you can create your own schedule.
272       If you run crontab -e, then an editor will load with your user-specific
273       cron schedule. In that editor, you can add your own schedule lines. You
274       could start by adapting the default schedule listed earlier, or you
275       could read the crontab(5) documentation for advanced scheduling
276       techniques. Please do use the full path and --exec-path techniques from
277       the default schedule to ensure you are executing the correct binaries
278       in your schedule.
279

BACKGROUND MAINTENANCE ON LINUX SYSTEMD SYSTEMS

281       While Linux supports cron, depending on the distribution, cron may be
282       an optional package not necessarily installed. On modern Linux
283       distributions, systemd timers are superseding it.
284
285       If user systemd timers are available, they will be used as a
286       replacement of cron.
287
288       In this case, git maintenance start will create user systemd timer
289       units and start the timers. The current list of user-scheduled tasks
290       can be found by running systemctl --user list-timers. The timers
291       written by git maintenance start are similar to this:
292
293           $ systemctl --user list-timers
294           NEXT                         LEFT          LAST                         PASSED     UNIT                         ACTIVATES
295           Thu 2021-04-29 19:00:00 CEST 42min left    Thu 2021-04-29 18:00:11 CEST 17min ago  git-maintenance@hourly.timer git-maintenance@hourly.service
296           Fri 2021-04-30 00:00:00 CEST 5h 42min left Thu 2021-04-29 00:00:11 CEST 18h ago    git-maintenance@daily.timer  git-maintenance@daily.service
297           Mon 2021-05-03 00:00:00 CEST 3 days left   Mon 2021-04-26 00:00:11 CEST 3 days ago git-maintenance@weekly.timer git-maintenance@weekly.service
298
299       One timer is registered for each --schedule=<frequency> option.
300
301       The definition of the systemd units can be inspected in the following
302       files:
303
304           ~/.config/systemd/user/git-maintenance@.timer
305           ~/.config/systemd/user/git-maintenance@.service
306           ~/.config/systemd/user/timers.target.wants/git-maintenance@hourly.timer
307           ~/.config/systemd/user/timers.target.wants/git-maintenance@daily.timer
308           ~/.config/systemd/user/timers.target.wants/git-maintenance@weekly.timer
309
310       git maintenance start will overwrite these files and start the timer
311       again with systemctl --user, so any customization should be done by
312       creating a drop-in file, i.e. a .conf suffixed file in the
313       ~/.config/systemd/user/git-maintenance@.service.d directory.
314
315       git maintenance stop will stop the user systemd timers and delete the
316       above mentioned files.
317
318       For more details, see systemd.timer(5).
319

BACKGROUND MAINTENANCE ON MACOS SYSTEMS

321       While macOS technically supports cron, using crontab -e requires
322       elevated privileges and the executed process does not have a full user
323       context. Without a full user context, Git and its credential helpers
324       cannot access stored credentials, so some maintenance tasks are not
325       functional.
326
327       Instead, git maintenance start interacts with the launchctl tool, which
328       is the recommended way to schedule timed jobs in macOS. Scheduling
329       maintenance through git maintenance (start|stop) requires some
330       launchctl features available only in macOS 10.11 or later.
331
332       Your user-specific scheduled tasks are stored as XML-formatted .plist
333       files in ~/Library/LaunchAgents/. You can see the currently-registered
334       tasks using the following command:
335
336           $ ls ~/Library/LaunchAgents/org.git-scm.git*
337           org.git-scm.git.daily.plist
338           org.git-scm.git.hourly.plist
339           org.git-scm.git.weekly.plist
340
341       One task is registered for each --schedule=<frequency> option. To
342       inspect how the XML format describes each schedule, open one of these
343       .plist files in an editor and inspect the <array> element following the
344       <key>StartCalendarInterval</key> element.
345
346       git maintenance start will overwrite these files and register the tasks
347       again with launchctl, so any customizations should be done by creating
348       your own .plist files with distinct names. Similarly, the git
349       maintenance stop command will unregister the tasks with launchctl and
350       delete the .plist files.
351
352       To create more advanced customizations to your background tasks, see
353       launchctl.plist(5) for more information.
354

BACKGROUND MAINTENANCE ON WINDOWS SYSTEMS

356       Windows does not support cron and instead has its own system for
357       scheduling background tasks. The git maintenance start command uses the
358       schtasks command to submit tasks to this system. You can inspect all
359       background tasks using the Task Scheduler application. The tasks added
360       by Git have names of the form Git Maintenance (<frequency>). The Task
361       Scheduler GUI has ways to inspect these tasks, but you can also export
362       the tasks to XML files and view the details there.
363
364       Note that since Git is a console application, these background tasks
365       create a console window visible to the current user. This can be
366       changed manually by selecting the "Run whether user is logged in or
367       not" option in Task Scheduler. This change requires a password input,
368       which is why git maintenance start does not select it by default.
369
370       If you want to customize the background tasks, please rename the tasks
371       so future calls to git maintenance (start|stop) do not overwrite your
372       custom tasks.
373

CONFIGURATION

375       Everything below this line in this section is selectively included from
376       the git-config(1) documentation. The content is the same as what’s
377       found there:
378
379       maintenance.auto
380           This boolean config option controls whether some commands run git
381           maintenance run --auto after doing their normal work. Defaults to
382           true.
383
384       maintenance.strategy
385           This string config option provides a way to specify one of a few
386           recommended schedules for background maintenance. This only affects
387           which tasks are run during git maintenance run --schedule=X
388           commands, provided no --task=<task> arguments are provided.
389           Further, if a maintenance.<task>.schedule config value is set, then
390           that value is used instead of the one provided by
391           maintenance.strategy. The possible strategy strings are:
392
393none: This default setting implies no task are run at any
394               schedule.
395
396incremental: This setting optimizes for performing small
397               maintenance activities that do not delete any data. This does
398               not schedule the gc task, but runs the prefetch and
399               commit-graph tasks hourly, the loose-objects and
400               incremental-repack tasks daily, and the pack-refs task weekly.
401
402       maintenance.<task>.enabled
403           This boolean config option controls whether the maintenance task
404           with name <task> is run when no --task option is specified to git
405           maintenance run. These config values are ignored if a --task option
406           exists. By default, only maintenance.gc.enabled is true.
407
408       maintenance.<task>.schedule
409           This config option controls whether or not the given <task> runs
410           during a git maintenance run --schedule=<frequency> command. The
411           value must be one of "hourly", "daily", or "weekly".
412
413       maintenance.commit-graph.auto
414           This integer config option controls how often the commit-graph task
415           should be run as part of git maintenance run --auto. If zero, then
416           the commit-graph task will not run with the --auto option. A
417           negative value will force the task to run every time. Otherwise, a
418           positive value implies the command should run when the number of
419           reachable commits that are not in the commit-graph file is at least
420           the value of maintenance.commit-graph.auto. The default value is
421           100.
422
423       maintenance.loose-objects.auto
424           This integer config option controls how often the loose-objects
425           task should be run as part of git maintenance run --auto. If zero,
426           then the loose-objects task will not run with the --auto option. A
427           negative value will force the task to run every time. Otherwise, a
428           positive value implies the command should run when the number of
429           loose objects is at least the value of
430           maintenance.loose-objects.auto. The default value is 100.
431
432       maintenance.incremental-repack.auto
433           This integer config option controls how often the
434           incremental-repack task should be run as part of git maintenance
435           run --auto. If zero, then the incremental-repack task will not run
436           with the --auto option. A negative value will force the task to run
437           every time. Otherwise, a positive value implies the command should
438           run when the number of pack-files not in the multi-pack-index is at
439           least the value of maintenance.incremental-repack.auto. The default
440           value is 10.
441

GIT

443       Part of the git(1) suite
444
445
446
447Git 2.39.1                        2023-01-13                GIT-MAINTENANCE(1)
Impressum