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.46.1.603.g94b60adee3
10 .TH "GIT\-MAINTENANCE" "1" "2024-09-20" "Git 2\&.46\&.1\&.603\&.g94b60a" "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 add\fR or \fBgit fetch\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 maintenance\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\&.<task>\&.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
64 \fBgit maintenance run \-\-scheduled\fR
70 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\&.
75 Initialize Git config values so any scheduled maintenance will start running on this repository\&. This adds the repository to the
76 \fBmaintenance\&.repo\fR
77 config variable in the current user\(cqs global config, or the config specified by \-\-config\-file option, and enables some recommended configuration values for
78 \fBmaintenance\&.<task>\&.schedule\fR\&. The tasks that are enabled are safe for running in the background without disrupting foreground processes\&.
82 subcommand will also set the
83 \fBmaintenance\&.strategy\fR
85 \fBincremental\fR, if this value is not previously set\&. The
87 strategy uses the following schedule for each maintenance task:
108 \fBcommit\-graph\fR: hourly\&.
119 \fBprefetch\fR: hourly\&.
130 \fBloose\-objects\fR: daily\&.
141 \fBincremental\-repack\fR: daily\&.
144 \fBgit maintenance register\fR
145 will also disable foreground maintenance by setting
146 \fBmaintenance\&.auto = false\fR
147 in the current repository\&. This config setting will remain after a
148 \fBgit maintenance unregister\fR
154 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\&.
158 subcommand will report an error if the current repository is not already registered\&. Use the
160 option to return success even when the current repository is not registered\&.
170 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
172 files that were in the previous
173 \fBcommit\-graph\-chain\fR
174 file\&. They will be deleted by a later run based on the expiration delay\&.
181 task updates the object directory with the latest objects from all registered remotes\&. For each remote, a
183 command is run\&. The configured refspec is modified to place all requested refs within
184 \fBrefs/prefetch/\fR\&. Also, tags are not updated\&.
186 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\&.
189 \fBremote\&.<name>\&.skipFetchAll\fR
190 configuration can be used to exclude a particular remote from getting prefetched\&.
195 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
197 for more details on garbage collection in Git\&.
204 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
206 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
210 tasks at the same time\&.
216 \fBincremental\-repack\fR
217 job repacks the object directory using the
218 \fBmulti\-pack\-index\fR
219 feature\&. In order to prevent race conditions with concurrent Git commands, it follows a two\-step process\&. First, it calls
220 \fBgit multi\-pack\-index expire\fR
221 to delete pack\-files unreferenced by the
222 \fBmulti\-pack\-index\fR
223 file\&. Second, it calls
224 \fBgit multi\-pack\-index repack\fR
225 to select several small pack\-files and repack them into a bigger one, and then update the
226 \fBmulti\-pack\-index\fR
227 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
228 \fBgit multi\-pack\-index expire\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
229 \fB\-\-batch\-size\fR
233 \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\&.
240 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
241 \fBgit-pack-refs\fR(1)
242 for more information\&.
248 When combined with the
250 subcommand, run maintenance tasks only if certain thresholds are met\&. For example, the
252 task runs when the number of loose objects exceeds the number stored in the
254 config setting, or when the number of pack\-files exceeds the
255 \fBgc\&.autoPackLimit\fR
256 config setting\&. Not compatible with the
263 When combined with the
265 subcommand, run maintenance tasks only if certain time conditions are met, as specified by the
266 \fBmaintenance\&.<task>\&.schedule\fR
267 config value for each
268 \fB<task>\fR\&. This config value specifies a number of seconds since the last time that task ran, according to the
269 \fBmaintenance\&.<task>\&.lastRun\fR
270 config value\&. The tasks that are tested are those provided by the
271 \fB\-\-task=<task>\fR
272 option(s) or those with
273 \fBmaintenance\&.<task>\&.enabled\fR
279 Do not report progress or other information over
285 If this option is specified one or more times, then only run the specified tasks in the specified order\&. If no
286 \fB\-\-task=<task>\fR
287 arguments are specified, then only the tasks with
288 \fBmaintenance\&.<task>\&.enabled\fR
291 are considered\&. See the
293 section for the list of accepted
298 \-\-scheduler=auto|crontab|systemd\-timer|launchctl|schtasks
300 When combined with the
302 subcommand, specify the scheduler for running the hourly, daily and weekly executions of
303 \fBgit maintenance run\fR\&. Possible values for
316 is specified, the appropriate platform\-specific scheduler is used; on Linux,
318 is used if available, otherwise
319 \fBcrontab\fR\&. Default is
322 .SH "TROUBLESHOOTING"
324 The \fBgit maintenance\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\&.
326 Users may find some cases where scheduled maintenance tasks do not run as frequently as intended\&. Each \fBgit maintenance run\fR command takes a lock on the repository\(cqs object database, and this prevents other concurrent \fBgit maintenance run\fR commands from running on the same repository\&. Without this safeguard, competing processes could leave the repository in an unpredictable state\&.
328 The background maintenance schedule runs \fBgit maintenance run\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\&. Depending on the number of registered repositories and their sizes, this process may take longer than an hour\&. In this case, multiple \fBgit maintenance run\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\&.
330 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\&.
332 Expert users may consider scheduling their own maintenance tasks using a different schedule than is available through \fBgit maintenance start\fR and Git configuration options\&. These users should be aware of the object database lock and how concurrent \fBgit maintenance run\fR commands behave\&. Further, the \fBgit gc\fR command should not be combined with \fBgit maintenance run\fR commands\&. \fBgit gc\fR modifies the object database but does not take the lock in the same way as \fBgit maintenance run\fR\&. If possible, use \fBgit maintenance run \-\-task=gc\fR instead of \fBgit gc\fR\&.
334 The following sections describe the mechanisms put in place to run background maintenance by \fBgit maintenance start\fR and how to customize them\&.
335 .SH "BACKGROUND MAINTENANCE ON POSIX SYSTEMS"
337 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 \-l\fR\&. The schedule written by \fBgit maintenance start\fR is similar to this:
343 # BEGIN GIT MAINTENANCE SCHEDULE
344 # The following schedule was created by Git
345 # Any edits made in this region might be
346 # replaced in the future by a Git command\&.
348 0 1\-23 * * * "/<path>/git" \-\-exec\-path="/<path>" for\-each\-repo \-\-config=maintenance\&.repo maintenance run \-\-schedule=hourly
349 0 0 * * 1\-6 "/<path>/git" \-\-exec\-path="/<path>" for\-each\-repo \-\-config=maintenance\&.repo maintenance run \-\-schedule=daily
350 0 0 * * 0 "/<path>/git" \-\-exec\-path="/<path>" for\-each\-repo \-\-config=maintenance\&.repo maintenance run \-\-schedule=weekly
352 # END GIT MAINTENANCE SCHEDULE
358 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 maintenance stop\fR or overwritten by \fBgit maintenance start\fR\&.
360 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 maintenance start\fR was issued independent of \fBPATH\fR\&. If the same user runs \fBgit maintenance start\fR with multiple Git executables, then only the latest executable is used\&.
362 These commands use \fBgit for\-each\-repo \-\-config=maintenance\&.repo\fR to run \fBgit maintenance run \-\-schedule=<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 maintenance\fR process then determines which maintenance tasks are configured to run on each repository with each \fB<frequency>\fR using the \fBmaintenance\&.<task>\&.schedule\fR config options\&. These values are loaded from the global or repository config values\&.
364 If the config values are insufficient to achieve your desired background maintenance schedule, then you can create your own schedule\&. If you run \fBcrontab \-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\&.
365 .SH "BACKGROUND MAINTENANCE ON LINUX SYSTEMD SYSTEMS"
367 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\&.
369 If user systemd timers are available, they will be used as a replacement of \fBcron\fR\&.
371 In this case, \fBgit maintenance start\fR will create user systemd timer units and start the timers\&. The current list of user\-scheduled tasks can be found by running \fBsystemctl \-\-user list\-timers\fR\&. The timers written by \fBgit maintenance start\fR are similar to this:
377 $ systemctl \-\-user list\-timers
378 NEXT LEFT LAST PASSED UNIT ACTIVATES
379 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
380 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
381 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
387 One timer is registered for each \fB\-\-schedule=<frequency>\fR option\&.
389 The definition of the systemd units can be inspected in the following files:
395 ~/\&.config/systemd/user/git\-maintenance@\&.timer
396 ~/\&.config/systemd/user/git\-maintenance@\&.service
397 ~/\&.config/systemd/user/timers\&.target\&.wants/git\-maintenance@hourly\&.timer
398 ~/\&.config/systemd/user/timers\&.target\&.wants/git\-maintenance@daily\&.timer
399 ~/\&.config/systemd/user/timers\&.target\&.wants/git\-maintenance@weekly\&.timer
405 \fBgit maintenance start\fR will overwrite these files and start the timer again with \fBsystemctl \-\-user\fR, so any customization should be done by creating a drop\-in file, i\&.e\&. a \fB\&.conf\fR suffixed file in the \fB~/\&.config/systemd/user/git\-maintenance@\&.service\&.d\fR directory\&.
407 \fBgit maintenance stop\fR will stop the user systemd timers and delete the above mentioned files\&.
409 For more details, see \fBsystemd\&.timer(5)\fR\&.
410 .SH "BACKGROUND MAINTENANCE ON MACOS SYSTEMS"
412 While macOS technically supports \fBcron\fR, using \fBcrontab \-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\&.
414 Instead, \fBgit maintenance start\fR interacts with the \fBlaunchctl\fR tool, which is the recommended way to schedule timed jobs in macOS\&. Scheduling maintenance through \fBgit maintenance (start|stop)\fR requires some \fBlaunchctl\fR features available only in macOS 10\&.11 or later\&.
416 Your user\-specific scheduled tasks are stored as XML\-formatted \fB\&.plist\fR files in \fB~/Library/LaunchAgents/\fR\&. You can see the currently\-registered tasks using the following command:
422 $ ls ~/Library/LaunchAgents/org\&.git\-scm\&.git*
423 org\&.git\-scm\&.git\&.daily\&.plist
424 org\&.git\-scm\&.git\&.hourly\&.plist
425 org\&.git\-scm\&.git\&.weekly\&.plist
431 One task is registered for each \fB\-\-schedule=<frequency>\fR option\&. To inspect how the XML format describes each schedule, open one of these \fB\&.plist\fR files in an editor and inspect the \fB<array>\fR element following the \fB<key>StartCalendarInterval</key>\fR element\&.
433 \fBgit maintenance start\fR will overwrite these files and register the tasks again with \fBlaunchctl\fR, so any customizations should be done by creating your own \fB\&.plist\fR files with distinct names\&. Similarly, the \fBgit maintenance stop\fR command will unregister the tasks with \fBlaunchctl\fR and delete the \fB\&.plist\fR files\&.
435 To create more advanced customizations to your background tasks, see launchctl\&.plist(5) for more information\&.
436 .SH "BACKGROUND MAINTENANCE ON WINDOWS SYSTEMS"
438 Windows does not support \fBcron\fR and instead has its own system for scheduling background tasks\&. The \fBgit maintenance start\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 Maintenance (<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\&.
440 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 maintenance start\fR does not select it by default\&.
442 If you want to customize the background tasks, please rename the tasks so future calls to \fBgit maintenance (start|stop)\fR do not overwrite your custom tasks\&.
445 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:
449 This boolean config option controls whether some commands run
450 \fBgit maintenance run \-\-auto\fR
451 after doing their normal work\&. Defaults to true\&.
454 maintenance\&.autoDetach
456 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\&.
458 If unset, the value of
459 \fBgc\&.autoDetach\fR
460 is used as a fallback\&. Defaults to true if both are unset, meaning that the maintenance process will detach\&.
463 maintenance\&.strategy
465 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
466 \fBgit maintenance run \-\-schedule=X\fR
467 commands, provided no
468 \fB\-\-task=<task>\fR
469 arguments are provided\&. Further, if a
470 \fBmaintenance\&.<task>\&.schedule\fR
471 config value is set, then that value is used instead of the one provided by
472 \fBmaintenance\&.strategy\fR\&. The possible strategy strings are:
482 \fBnone\fR: This default setting implies no tasks are run at any schedule\&.
493 \fBincremental\fR: This setting optimizes for performing small maintenance activities that do not delete any data\&. This does not schedule the
502 \fBincremental\-repack\fR
509 maintenance\&.<task>\&.enabled
511 This boolean config option controls whether the maintenance task with name
515 option is specified to
516 \fBgit maintenance run\fR\&. These config values are ignored if a
518 option exists\&. By default, only
519 \fBmaintenance\&.gc\&.enabled\fR
523 maintenance\&.<task>\&.schedule
525 This config option controls whether or not the given
528 \fBgit maintenance run \-\-schedule=<frequency>\fR
529 command\&. The value must be one of "hourly", "daily", or "weekly"\&.
532 maintenance\&.commit\-graph\&.auto
534 This integer config option controls how often the
536 task should be run as part of
537 \fBgit maintenance run \-\-auto\fR\&. If zero, then the
539 task will not run with the
541 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
542 \fBmaintenance\&.commit\-graph\&.auto\fR\&. The default value is 100\&.
545 maintenance\&.loose\-objects\&.auto
547 This integer config option controls how often the
549 task should be run as part of
550 \fBgit maintenance run \-\-auto\fR\&. If zero, then the
552 task will not run with the
554 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
555 \fBmaintenance\&.loose\-objects\&.auto\fR\&. The default value is 100\&.
558 maintenance\&.incremental\-repack\&.auto
560 This integer config option controls how often the
561 \fBincremental\-repack\fR
562 task should be run as part of
563 \fBgit maintenance run \-\-auto\fR\&. If zero, then the
564 \fBincremental\-repack\fR
565 task will not run with the
567 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
568 \fBmaintenance\&.incremental\-repack\&.auto\fR\&. The default value is 10\&.
572 Part of the \fBgit\fR(1) suite