2 .\" Title: git-maintenance
3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets v1.79.2 <http://docbook.sf.net/>
7 .\" Source: Git 2.48.1.157.g3b0d05c4a7
10 .TH "GIT\-MAINTENANCE" "1" "2025-01-29" "Git 2\&.48\&.1\&.157\&.g3b0d05" "Git Manual"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 git-maintenance \- Run tasks to optimize Git repository data
35 \fIgit maintenance\fR run [<options>]
36 \fIgit maintenance\fR start [\-\-scheduler=<scheduler>]
37 \fIgit maintenance\fR (stop|register|unregister) [<options>]
41 Run tasks to optimize Git repository data, speeding up other Git commands and reducing storage requirements for the repository\&.
43 Git commands that add repository data, such as \fBgit\fR \fBadd\fR or \fBgit\fR \fBfetch\fR, are optimized for a responsive user experience\&. These commands do not take time to optimize the Git data, since such optimizations scale with the full size of the repository while these user commands each perform a relatively small action\&.
45 The \fBgit\fR \fBmaintenance\fR command provides flexibility for how to optimize the Git repository\&.
50 Run one or more maintenance tasks\&. If one or more
52 options are specified, then those tasks are run in that order\&. Otherwise, the tasks are determined by which
53 \fBmaintenance\&.\fR\fI<task>\fR\fB\&.enabled\fR
54 config options are true\&. By default, only
55 \fBmaintenance\&.gc\&.enabled\fR
61 Start running maintenance on the current repository\&. This performs the same config updates as the
63 subcommand, then updates the background scheduler to run
73 Halt the background maintenance schedule\&. The current repository is not removed from the list of maintained repositories, in case the background maintenance is restarted later\&.
78 Initialize Git config values so any scheduled maintenance will start running on this repository\&. This adds the repository to the
79 \fBmaintenance\&.repo\fR
80 config variable in the current user\(cqs global config, or the config specified by \-\-config\-file option, and enables some recommended configuration values for
81 \fBmaintenance\&.\fR\fI<task>\fR\fB\&.schedule\fR\&. The tasks that are enabled are safe for running in the background without disrupting foreground processes\&.
85 subcommand will also set the
86 \fBmaintenance\&.strategy\fR
88 \fBincremental\fR, if this value is not previously set\&. The
90 strategy uses the following schedule for each maintenance task:
100 \fBgc\fR: disabled\&.
111 \fBcommit\-graph\fR: hourly\&.
122 \fBprefetch\fR: hourly\&.
133 \fBloose\-objects\fR: daily\&.
144 \fBincremental\-repack\fR: daily\&.
150 will also disable foreground maintenance by setting
151 \fBmaintenance\&.auto\fR
154 in the current repository\&. This config setting will remain after a
163 Remove the current repository from background maintenance\&. This only removes the repository from the configured list\&. It does not stop the background maintenance processes from running\&.
167 subcommand will report an error if the current repository is not already registered\&. Use the
169 option to return success even when the current repository is not registered\&.
179 files incrementally, then verifies that the written data is correct\&. The incremental write is safe to run alongside concurrent Git processes since it will not expire \&.\fBgraph\fR
180 files that were in the previous
181 \fBcommit\-graph\-chain\fR
182 file\&. They will be deleted by a later run based on the expiration delay\&.
189 task updates the object directory with the latest objects from all registered remotes\&. For each remote, a
192 command is run\&. The configured refspec is modified to place all requested refs within
193 \fBrefs/prefetch/\fR\&. Also, tags are not updated\&.
195 This is done to avoid disrupting the remote\-tracking branches\&. The end users expect these refs to stay unmoved unless they initiate a fetch\&. However, with the prefetch task, the objects necessary to complete a later real fetch would already be obtained, making the real fetch faster\&. In the ideal case, it will just become an update to a bunch of remote\-tracking branches without any object transfer\&.
198 \fBremote\&.\fR\fI<name>\fR\fB\&.skipFetchAll\fR
199 configuration can be used to exclude a particular remote from getting prefetched\&.
204 Clean up unnecessary files and optimize the local repository\&. "GC" stands for "garbage collection," but this task performs many smaller tasks\&. This task can be expensive for large repositories, as it repacks all Git objects into a single pack\-file\&. It can also be disruptive in some situations, as it deletes stale data\&. See
206 for more details on garbage collection in Git\&.
213 job cleans up loose objects and places them into pack\-files\&. In order to prevent race conditions with concurrent Git commands, it follows a two\-step process\&. First, it deletes any loose objects that already exist in a pack\-file; concurrent Git processes will examine the pack\-file for the object data instead of the loose object\&. Second, it creates a new pack\-file (starting with "loose\-") containing a batch of loose objects\&. The batch size is limited to 50 thousand objects to prevent the job from taking too long on a repository with many loose objects\&. The
215 task writes unreachable objects as loose objects to be cleaned up by a later step only if they are not re\-added to a pack\-file; for this reason it is not advisable to enable both the
219 tasks at the same time\&.
225 \fBincremental\-repack\fR
226 job repacks the object directory using the
227 \fBmulti\-pack\-index\fR
228 feature\&. In order to prevent race conditions with concurrent Git commands, it follows a two\-step process\&. First, it calls
230 \fBmulti\-pack\-index\fR
232 to delete pack\-files unreferenced by the
233 \fBmulti\-pack\-index\fR
234 file\&. Second, it calls
236 \fBmulti\-pack\-index\fR
238 to select several small pack\-files and repack them into a bigger one, and then update the
239 \fBmulti\-pack\-index\fR
240 entries that refer to the small pack\-files to refer to the new pack\-file\&. This prepares those small pack\-files for deletion upon the next run of
242 \fBmulti\-pack\-index\fR
243 \fBexpire\fR\&. The selection of the small pack\-files is such that the expected size of the big pack\-file is at least the batch size; see the
244 \fB\-\-batch\-size\fR
248 \fBgit-multi-pack-index\fR(1)\&. The default batch\-size is zero, which is a special case that attempts to repack all pack\-files into a single pack\-file\&.
255 task collects the loose reference files and collects them into a single file\&. This speeds up operations that need to iterate across many references\&. See
256 \fBgit-pack-refs\fR(1)
257 for more information\&.
263 When combined with the
265 subcommand, run maintenance tasks only if certain thresholds are met\&. For example, the
267 task runs when the number of loose objects exceeds the number stored in the
269 config setting, or when the number of pack\-files exceeds the
270 \fBgc\&.autoPackLimit\fR
271 config setting\&. Not compatible with the
278 When combined with the
280 subcommand, run maintenance tasks only if certain time conditions are met, as specified by the
281 \fBmaintenance\&.\fR\fI<task>\fR\fB\&.schedule\fR
282 config value for each
283 \fI<task>\fR\&. This config value specifies a number of seconds since the last time that task ran, according to the
284 \fBmaintenance\&.\fR\fI<task>\fR\fB\&.lastRun\fR
285 config value\&. The tasks that are tested are those provided by the
286 \fB\-\-task=\fR\fI<task>\fR
287 option(s) or those with
288 \fBmaintenance\&.\fR\fI<task>\fR\fB\&.enabled\fR
294 Do not report progress or other information over
300 If this option is specified one or more times, then only run the specified tasks in the specified order\&. If no
301 \fB\-\-task=\fR\fI<task>\fR
302 arguments are specified, then only the tasks with
303 \fBmaintenance\&.\fR\fI<task>\fR\fB\&.enabled\fR
306 are considered\&. See the
308 section for the list of accepted
313 \-\-scheduler=auto|crontab|systemd\-timer|launchctl|schtasks
315 When combined with the
317 subcommand, specify the scheduler for running the hourly, daily and weekly executions of
320 \fBrun\fR\&. Possible values for
333 is specified, the appropriate platform\-specific scheduler is used; on Linux,
335 is used if available, otherwise
336 \fBcrontab\fR\&. Default is
339 .SH "TROUBLESHOOTING"
341 The \fBgit\fR \fBmaintenance\fR command is designed to simplify the repository maintenance patterns while minimizing user wait time during Git commands\&. A variety of configuration options are available to allow customizing this process\&. The default maintenance options focus on operations that complete quickly, even on large repositories\&.
343 Users may find some cases where scheduled maintenance tasks do not run as frequently as intended\&. Each \fBgit\fR \fBmaintenance\fR \fBrun\fR command takes a lock on the repository\(cqs object database, and this prevents other concurrent \fBgit\fR \fBmaintenance\fR \fBrun\fR commands from running on the same repository\&. Without this safeguard, competing processes could leave the repository in an unpredictable state\&.
345 The background maintenance schedule runs \fBgit\fR \fBmaintenance\fR \fBrun\fR processes on an hourly basis\&. Each run executes the "hourly" tasks\&. At midnight, that process also executes the "daily" tasks\&. At midnight on the first day of the week, that process also executes the "weekly" tasks\&. A single process iterates over each registered repository, performing the scheduled tasks for that frequency\&. The processes are scheduled to a random minute of the hour per client to spread out the load that multiple clients might generate (e\&.g\&. from prefetching)\&. Depending on the number of registered repositories and their sizes, this process may take longer than an hour\&. In this case, multiple \fBgit\fR \fBmaintenance\fR \fBrun\fR commands may run on the same repository at the same time, colliding on the object database lock\&. This results in one of the two tasks not running\&.
347 If you find that some maintenance windows are taking longer than one hour to complete, then consider reducing the complexity of your maintenance tasks\&. For example, the \fBgc\fR task is much slower than the \fBincremental\-repack\fR task\&. However, this comes at a cost of a slightly larger object database\&. Consider moving more expensive tasks to be run less frequently\&.
349 Expert users may consider scheduling their own maintenance tasks using a different schedule than is available through \fBgit\fR \fBmaintenance\fR \fBstart\fR and Git configuration options\&. These users should be aware of the object database lock and how concurrent \fBgit\fR \fBmaintenance\fR \fBrun\fR commands behave\&. Further, the \fBgit\fR \fBgc\fR command should not be combined with \fBgit\fR \fBmaintenance\fR \fBrun\fR commands\&. \fBgit\fR \fBgc\fR modifies the object database but does not take the lock in the same way as \fBgit\fR \fBmaintenance\fR \fBrun\fR\&. If possible, use \fBgit\fR \fBmaintenance\fR \fBrun\fR \fB\-\-task=gc\fR instead of \fBgit\fR \fBgc\fR\&.
351 The following sections describe the mechanisms put in place to run background maintenance by \fBgit\fR \fBmaintenance\fR \fBstart\fR and how to customize them\&.
352 .SH "BACKGROUND MAINTENANCE ON POSIX SYSTEMS"
354 The standard mechanism for scheduling background tasks on POSIX systems is cron(8)\&. This tool executes commands based on a given schedule\&. The current list of user\-scheduled tasks can be found by running \fBcrontab\fR \fB\-l\fR\&. The schedule written by \fBgit\fR \fBmaintenance\fR \fBstart\fR is similar to this:
360 # BEGIN GIT MAINTENANCE SCHEDULE
361 # The following schedule was created by Git
362 # Any edits made in this region might be
363 # replaced in the future by a Git command\&.
365 0 1\-23 * * * "/<path>/git" \-\-exec\-path="/<path>" for\-each\-repo \-\-config=maintenance\&.repo maintenance run \-\-schedule=hourly
366 0 0 * * 1\-6 "/<path>/git" \-\-exec\-path="/<path>" for\-each\-repo \-\-config=maintenance\&.repo maintenance run \-\-schedule=daily
367 0 0 * * 0 "/<path>/git" \-\-exec\-path="/<path>" for\-each\-repo \-\-config=maintenance\&.repo maintenance run \-\-schedule=weekly
369 # END GIT MAINTENANCE SCHEDULE
375 The comments are used as a region to mark the schedule as written by Git\&. Any modifications within this region will be completely deleted by \fBgit\fR \fBmaintenance\fR \fBstop\fR or overwritten by \fBgit\fR \fBmaintenance\fR \fBstart\fR\&.
377 The \fBcrontab\fR entry specifies the full path of the \fBgit\fR executable to ensure that the executed \fBgit\fR command is the same one with which \fBgit\fR \fBmaintenance\fR \fBstart\fR was issued independent of \fBPATH\fR\&. If the same user runs \fBgit\fR \fBmaintenance\fR \fBstart\fR with multiple Git executables, then only the latest executable is used\&.
379 These commands use \fBgit\fR \fBfor\-each\-repo\fR \fB\-\-config=maintenance\&.repo\fR to run \fBgit\fR \fBmaintenance\fR \fBrun\fR \fB\-\-schedule=\fR\fI<frequency>\fR on each repository listed in the multi\-valued \fBmaintenance\&.repo\fR config option\&. These are typically loaded from the user\-specific global config\&. The \fBgit\fR \fBmaintenance\fR process then determines which maintenance tasks are configured to run on each repository with each \fI<frequency>\fR using the \fBmaintenance\&.\fR\fI<task>\fR\fB\&.schedule\fR config options\&. These values are loaded from the global or repository config values\&.
381 If the config values are insufficient to achieve your desired background maintenance schedule, then you can create your own schedule\&. If you run \fBcrontab\fR \fB\-e\fR, then an editor will load with your user\-specific \fBcron\fR schedule\&. In that editor, you can add your own schedule lines\&. You could start by adapting the default schedule listed earlier, or you could read the crontab(5) documentation for advanced scheduling techniques\&. Please do use the full path and \fB\-\-exec\-path\fR techniques from the default schedule to ensure you are executing the correct binaries in your schedule\&.
382 .SH "BACKGROUND MAINTENANCE ON LINUX SYSTEMD SYSTEMS"
384 While Linux supports \fBcron\fR, depending on the distribution, \fBcron\fR may be an optional package not necessarily installed\&. On modern Linux distributions, systemd timers are superseding it\&.
386 If user systemd timers are available, they will be used as a replacement of \fBcron\fR\&.
388 In this case, \fBgit\fR \fBmaintenance\fR \fBstart\fR will create user systemd timer units and start the timers\&. The current list of user\-scheduled tasks can be found by running \fBsystemctl\fR \fB\-\-user\fR \fBlist\-timers\fR\&. The timers written by \fBgit\fR \fBmaintenance\fR \fBstart\fR are similar to this:
394 $ systemctl \-\-user list\-timers
395 NEXT LEFT LAST PASSED UNIT ACTIVATES
396 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
397 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
398 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
404 One timer is registered for each \fB\-\-schedule=\fR\fI<frequency>\fR option\&.
406 The definition of the systemd units can be inspected in the following files:
412 ~/\&.config/systemd/user/git\-maintenance@\&.timer
413 ~/\&.config/systemd/user/git\-maintenance@\&.service
414 ~/\&.config/systemd/user/timers\&.target\&.wants/git\-maintenance@hourly\&.timer
415 ~/\&.config/systemd/user/timers\&.target\&.wants/git\-maintenance@daily\&.timer
416 ~/\&.config/systemd/user/timers\&.target\&.wants/git\-maintenance@weekly\&.timer
422 \fBgit\fR \fBmaintenance\fR \fBstart\fR will overwrite these files and start the timer again with \fBsystemctl\fR \fB\-\-user\fR, so any customization should be done by creating a drop\-in file, i\&.e\&. a \&.\fBconf\fR suffixed file in the \fB~/\&.config/systemd/user/git\-maintenance@\&.service\&.d\fR directory\&.
424 \fBgit\fR \fBmaintenance\fR \fBstop\fR will stop the user systemd timers and delete the above mentioned files\&.
426 For more details, see \fBsystemd\&.timer\fR(\fB5\fR)\&.
427 .SH "BACKGROUND MAINTENANCE ON MACOS SYSTEMS"
429 While macOS technically supports \fBcron\fR, using \fBcrontab\fR \fB\-e\fR requires elevated privileges and the executed process does not have a full user context\&. Without a full user context, Git and its credential helpers cannot access stored credentials, so some maintenance tasks are not functional\&.
431 Instead, \fBgit\fR \fBmaintenance\fR \fBstart\fR interacts with the \fBlaunchctl\fR tool, which is the recommended way to schedule timed jobs in macOS\&. Scheduling maintenance through \fBgit\fR \fBmaintenance\fR (\fBstart\fR|\fBstop\fR) requires some \fBlaunchctl\fR features available only in macOS 10\&.11 or later\&.
433 Your user\-specific scheduled tasks are stored as XML\-formatted \&.\fBplist\fR files in \fB~/Library/LaunchAgents/\fR\&. You can see the currently\-registered tasks using the following command:
439 $ ls ~/Library/LaunchAgents/org\&.git\-scm\&.git*
440 org\&.git\-scm\&.git\&.daily\&.plist
441 org\&.git\-scm\&.git\&.hourly\&.plist
442 org\&.git\-scm\&.git\&.weekly\&.plist
448 One task is registered for each \fB\-\-schedule=\fR\fI<frequency>\fR option\&. To inspect how the XML format describes each schedule, open one of these \&.\fBplist\fR files in an editor and inspect the \fI<array>\fR element following the \fI<key>\fR\fBStartCalendarInterval\fR</key> element\&.
450 \fBgit\fR \fBmaintenance\fR \fBstart\fR will overwrite these files and register the tasks again with \fBlaunchctl\fR, so any customizations should be done by creating your own \&.\fBplist\fR files with distinct names\&. Similarly, the \fBgit\fR \fBmaintenance\fR \fBstop\fR command will unregister the tasks with \fBlaunchctl\fR and delete the \&.\fBplist\fR files\&.
452 To create more advanced customizations to your background tasks, see launchctl\&.plist(5) for more information\&.
453 .SH "BACKGROUND MAINTENANCE ON WINDOWS SYSTEMS"
455 Windows does not support \fBcron\fR and instead has its own system for scheduling background tasks\&. The \fBgit\fR \fBmaintenance\fR \fBstart\fR command uses the \fBschtasks\fR command to submit tasks to this system\&. You can inspect all background tasks using the Task Scheduler application\&. The tasks added by Git have names of the form \fBGit\fR \fBMaintenance\fR (\fI<frequency>\fR)\&. The Task Scheduler GUI has ways to inspect these tasks, but you can also export the tasks to XML files and view the details there\&.
457 Note that since Git is a console application, these background tasks create a console window visible to the current user\&. This can be changed manually by selecting the "Run whether user is logged in or not" option in Task Scheduler\&. This change requires a password input, which is why \fBgit\fR \fBmaintenance\fR \fBstart\fR does not select it by default\&.
459 If you want to customize the background tasks, please rename the tasks so future calls to \fBgit\fR \fBmaintenance\fR (\fBstart\fR|\fBstop\fR) do not overwrite your custom tasks\&.
462 Everything below this line in this section is selectively included from the \fBgit-config\fR(1) documentation\&. The content is the same as what\(cqs found there:
466 This boolean config option controls whether some commands run
471 after doing their normal work\&. Defaults to true\&.
474 maintenance\&.autoDetach
476 Many Git commands trigger automatic maintenance after they have written data into the repository\&. This boolean config option controls whether this automatic maintenance shall happen in the foreground or whether the maintenance process shall detach and continue to run in the background\&.
478 If unset, the value of
479 \fBgc\&.autoDetach\fR
480 is used as a fallback\&. Defaults to true if both are unset, meaning that the maintenance process will detach\&.
483 maintenance\&.strategy
485 This string config option provides a way to specify one of a few recommended schedules for background maintenance\&. This only affects which tasks are run during
490 commands, provided no
491 \fB\-\-task=\fR\fI<task>\fR
492 arguments are provided\&. Further, if a
493 \fBmaintenance\&.\fR\fI<task>\fR\fB\&.schedule\fR
494 config value is set, then that value is used instead of the one provided by
495 \fBmaintenance\&.strategy\fR\&. The possible strategy strings are:
505 \fBnone\fR: This default setting implies no tasks are run at any schedule\&.
516 \fBincremental\fR: This setting optimizes for performing small maintenance activities that do not delete any data\&. This does not schedule the
525 \fBincremental\-repack\fR
532 maintenance\&.<task>\&.enabled
534 This boolean config option controls whether the maintenance task with name
538 option is specified to
541 \fBrun\fR\&. These config values are ignored if a
543 option exists\&. By default, only
544 \fBmaintenance\&.gc\&.enabled\fR
548 maintenance\&.<task>\&.schedule
550 This config option controls whether or not the given
556 \fB\-\-schedule=\fR\fI<frequency>\fR
557 command\&. The value must be one of "hourly", "daily", or "weekly"\&.
560 maintenance\&.commit\-graph\&.auto
562 This integer config option controls how often the
564 task should be run as part of
568 \fB\-\-auto\fR\&. If zero, then the
570 task will not run with the
572 option\&. A negative value will force the task to run every time\&. Otherwise, a positive value implies the command should run when the number of reachable commits that are not in the commit\-graph file is at least the value of
573 \fBmaintenance\&.commit\-graph\&.auto\fR\&. The default value is 100\&.
576 maintenance\&.loose\-objects\&.auto
578 This integer config option controls how often the
580 task should be run as part of
584 \fB\-\-auto\fR\&. If zero, then the
586 task will not run with the
588 option\&. A negative value will force the task to run every time\&. Otherwise, a positive value implies the command should run when the number of loose objects is at least the value of
589 \fBmaintenance\&.loose\-objects\&.auto\fR\&. The default value is 100\&.
592 maintenance\&.incremental\-repack\&.auto
594 This integer config option controls how often the
595 \fBincremental\-repack\fR
596 task should be run as part of
600 \fB\-\-auto\fR\&. If zero, then the
601 \fBincremental\-repack\fR
602 task will not run with the
604 option\&. A negative value will force the task to run every time\&. Otherwise, a positive value implies the command should run when the number of pack\-files not in the multi\-pack\-index is at least the value of
605 \fBmaintenance\&.incremental\-repack\&.auto\fR\&. The default value is 10\&.
609 Part of the \fBgit\fR(1) suite