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)
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 and enables some recommended configuration values for
49           maintenance.<task>.schedule. The tasks that are enabled are safe
50           for running in the background without disrupting foreground
51           processes.
52
53           The register subcommand will also set the maintenance.strategy
54           config value to incremental, if this value is not previously set.
55           The incremental strategy uses the following schedule for each
56           maintenance task:
57
58gc: disabled.
59
60commit-graph: hourly.
61
62prefetch: hourly.
63
64loose-objects: daily.
65
66incremental-repack: daily.
67
68           git maintenance register will also disable foreground maintenance
69           by setting maintenance.auto = false in the current repository. This
70           config setting will remain after a git maintenance unregister
71           command.
72
73       unregister
74           Remove the current repository from background maintenance. This
75           only removes the repository from the configured list. It does not
76           stop the background maintenance processes from running.
77

TASKS

79       commit-graph
80           The commit-graph job updates the commit-graph files incrementally,
81           then verifies that the written data is correct. The incremental
82           write is safe to run alongside concurrent Git processes since it
83           will not expire .graph files that were in the previous
84           commit-graph-chain file. They will be deleted by a later run based
85           on the expiration delay.
86
87       prefetch
88           The prefetch task updates the object directory with the latest
89           objects from all registered remotes. For each remote, a git fetch
90           command is run. The configured refspec is modified to place all
91           requested refs within refs/prefetch/. Also, tags are 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
141       pack-refs
142           The pack-refs task collects the loose reference files and collects
143           them into a single file. This speeds up operations that need to
144           iterate across many references. See git-pack-refs(1) for more
145           information.
146

OPTIONS

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

TROUBLESHOOTING

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

BACKGROUND MAINTENANCE ON POSIX SYSTEMS

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

BACKGROUND MAINTENANCE ON LINUX SYSTEMD SYSTEMS

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

BACKGROUND MAINTENANCE ON MACOS SYSTEMS

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

BACKGROUND MAINTENANCE ON WINDOWS SYSTEMS

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

GIT

370       Part of the git(1) suite
371
372
373
374Git 2.36.1                        2022-05-05                GIT-MAINTENANCE(1)
Impressum