2 .\" Title: git-maintenance
3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
7 .\" Source: Git 2.42.0.rc1.11.gfc6bba66bc
10 .TH "GIT\-MAINTENANCE" "1" "2023\-08\-14" "Git 2\&.42\&.0\&.rc1\&.11\&.gf" "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>]
42 Run tasks to optimize Git repository data, speeding up other Git commands and reducing storage requirements for the repository\&.
44 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\&.
46 The \fBgit maintenance\fR command provides flexibility for how to optimize the Git repository\&.
51 Run one or more maintenance tasks\&. If one or more
53 options are specified, then those tasks are run in that order\&. Otherwise, the tasks are determined by which
54 \fBmaintenance\&.<task>\&.enabled\fR
55 config options are true\&. By default, only
56 \fBmaintenance\&.gc\&.enabled\fR
62 Start running maintenance on the current repository\&. This performs the same config updates as the
64 subcommand, then updates the background scheduler to run
65 \fBgit maintenance run \-\-scheduled\fR
71 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\&.
76 Initialize Git config values so any scheduled maintenance will start running on this repository\&. This adds the repository to the
77 \fBmaintenance\&.repo\fR
78 config variable in the current user\(cqs global config, or the config specified by \-\-config\-file option, and enables some recommended configuration values for
79 \fBmaintenance\&.<task>\&.schedule\fR\&. The tasks that are enabled are safe for running in the background without disrupting foreground processes\&.
83 subcommand will also set the
84 \fBmaintenance\&.strategy\fR
86 \fBincremental\fR, if this value is not previously set\&. The
88 strategy uses the following schedule for each maintenance task:
109 \fBcommit\-graph\fR: hourly\&.
120 \fBprefetch\fR: hourly\&.
131 \fBloose\-objects\fR: daily\&.
142 \fBincremental\-repack\fR: daily\&.
145 \fBgit maintenance register\fR
146 will also disable foreground maintenance by setting
147 \fBmaintenance\&.auto = false\fR
148 in the current repository\&. This config setting will remain after a
149 \fBgit maintenance unregister\fR
155 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\&.
159 subcommand will report an error if the current repository is not already registered\&. Use the
161 option to return success even when the current repository is not registered\&.
171 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
173 files that were in the previous
174 \fBcommit\-graph\-chain\fR
175 file\&. They will be deleted by a later run based on the expiration delay\&.
182 task updates the object directory with the latest objects from all registered remotes\&. For each remote, a
184 command is run\&. The configured refspec is modified to place all requested refs within
185 \fBrefs/prefetch/\fR\&. Also, tags are not updated\&.
187 This is done to avoid disrupting the remote\-tracking branches\&. The end users expect these refs to stay unmoved unless they initiate a fetch\&. With prefetch task, however, the objects necessary to complete a later real fetch would already be obtained, so the real fetch would go faster\&. In the ideal case, it will just become an update to a bunch of remote\-tracking branches without any object transfer\&.
192 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
194 for more details on garbage collection in Git\&.
201 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
203 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
207 tasks at the same time\&.
213 \fBincremental\-repack\fR
214 job repacks the object directory using the
215 \fBmulti\-pack\-index\fR
216 feature\&. In order to prevent race conditions with concurrent Git commands, it follows a two\-step process\&. First, it calls
217 \fBgit multi\-pack\-index expire\fR
218 to delete pack\-files unreferenced by the
219 \fBmulti\-pack\-index\fR
220 file\&. Second, it calls
221 \fBgit multi\-pack\-index repack\fR
222 to select several small pack\-files and repack them into a bigger one, and then update the
223 \fBmulti\-pack\-index\fR
224 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
225 \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
226 \fB\-\-batch\-size\fR
230 \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\&.
237 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
238 \fBgit-pack-refs\fR(1)
239 for more information\&.
245 When combined with the
247 subcommand, run maintenance tasks only if certain thresholds are met\&. For example, the
249 task runs when the number of loose objects exceeds the number stored in the
251 config setting, or when the number of pack\-files exceeds the
252 \fBgc\&.autoPackLimit\fR
253 config setting\&. Not compatible with the
260 When combined with the
262 subcommand, run maintenance tasks only if certain time conditions are met, as specified by the
263 \fBmaintenance\&.<task>\&.schedule\fR
264 config value for each
265 \fB<task>\fR\&. This config value specifies a number of seconds since the last time that task ran, according to the
266 \fBmaintenance\&.<task>\&.lastRun\fR
267 config value\&. The tasks that are tested are those provided by the
268 \fB\-\-task=<task>\fR
269 option(s) or those with
270 \fBmaintenance\&.<task>\&.enabled\fR
276 Do not report progress or other information over
282 If this option is specified one or more times, then only run the specified tasks in the specified order\&. If no
283 \fB\-\-task=<task>\fR
284 arguments are specified, then only the tasks with
285 \fBmaintenance\&.<task>\&.enabled\fR
288 are considered\&. See the
290 section for the list of accepted
295 \-\-scheduler=auto|crontab|systemd\-timer|launchctl|schtasks
297 When combined with the
299 subcommand, specify the scheduler for running the hourly, daily and weekly executions of
300 \fBgit maintenance run\fR\&. Possible values for
313 is specified, the appropriate platform\-specific scheduler is used; on Linux,
315 is used if available, otherwise
316 \fBcrontab\fR\&. Default is
319 .SH "TROUBLESHOOTING"
321 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\&.
323 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\&.
325 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\&.
327 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\&.
329 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\&.
331 The following sections describe the mechanisms put in place to run background maintenance by \fBgit maintenance start\fR and how to customize them\&.
332 .SH "BACKGROUND MAINTENANCE ON POSIX SYSTEMS"
334 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:
340 # BEGIN GIT MAINTENANCE SCHEDULE
341 # The following schedule was created by Git
342 # Any edits made in this region might be
343 # replaced in the future by a Git command\&.
345 0 1\-23 * * * "/<path>/git" \-\-exec\-path="/<path>" for\-each\-repo \-\-config=maintenance\&.repo maintenance run \-\-schedule=hourly
346 0 0 * * 1\-6 "/<path>/git" \-\-exec\-path="/<path>" for\-each\-repo \-\-config=maintenance\&.repo maintenance run \-\-schedule=daily
347 0 0 * * 0 "/<path>/git" \-\-exec\-path="/<path>" for\-each\-repo \-\-config=maintenance\&.repo maintenance run \-\-schedule=weekly
349 # END GIT MAINTENANCE SCHEDULE
356 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\&.
358 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\&.
360 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\&.
362 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\&.
363 .SH "BACKGROUND MAINTENANCE ON LINUX SYSTEMD SYSTEMS"
365 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\&.
367 If user systemd timers are available, they will be used as a replacement of \fBcron\fR\&.
369 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:
375 $ systemctl \-\-user list\-timers
376 NEXT LEFT LAST PASSED UNIT ACTIVATES
377 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
378 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
379 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
386 One timer is registered for each \fB\-\-schedule=<frequency>\fR option\&.
388 The definition of the systemd units can be inspected in the following files:
394 ~/\&.config/systemd/user/git\-maintenance@\&.timer
395 ~/\&.config/systemd/user/git\-maintenance@\&.service
396 ~/\&.config/systemd/user/timers\&.target\&.wants/git\-maintenance@hourly\&.timer
397 ~/\&.config/systemd/user/timers\&.target\&.wants/git\-maintenance@daily\&.timer
398 ~/\&.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
432 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\&.
434 \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\&.
436 To create more advanced customizations to your background tasks, see launchctl\&.plist(5) for more information\&.
437 .SH "BACKGROUND MAINTENANCE ON WINDOWS SYSTEMS"
439 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\&.
441 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\&.
443 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\&.
446 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:
450 This boolean config option controls whether some commands run
451 \fBgit maintenance run \-\-auto\fR
452 after doing their normal work\&. Defaults to true\&.
455 maintenance\&.strategy
457 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
458 \fBgit maintenance run \-\-schedule=X\fR
459 commands, provided no
460 \fB\-\-task=<task>\fR
461 arguments are provided\&. Further, if a
462 \fBmaintenance\&.<task>\&.schedule\fR
463 config value is set, then that value is used instead of the one provided by
464 \fBmaintenance\&.strategy\fR\&. The possible strategy strings are:
474 \fBnone\fR: This default setting implies no task are run at any schedule\&.
485 \fBincremental\fR: This setting optimizes for performing small maintenance activities that do not delete any data\&. This does not schedule the
494 \fBincremental\-repack\fR
501 maintenance\&.<task>\&.enabled
503 This boolean config option controls whether the maintenance task with name
507 option is specified to
508 \fBgit maintenance run\fR\&. These config values are ignored if a
510 option exists\&. By default, only
511 \fBmaintenance\&.gc\&.enabled\fR
515 maintenance\&.<task>\&.schedule
517 This config option controls whether or not the given
520 \fBgit maintenance run \-\-schedule=<frequency>\fR
521 command\&. The value must be one of "hourly", "daily", or "weekly"\&.
524 maintenance\&.commit\-graph\&.auto
526 This integer config option controls how often the
528 task should be run as part of
529 \fBgit maintenance run \-\-auto\fR\&. If zero, then the
531 task will not run with the
533 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
534 \fBmaintenance\&.commit\-graph\&.auto\fR\&. The default value is 100\&.
537 maintenance\&.loose\-objects\&.auto
539 This integer config option controls how often the
541 task should be run as part of
542 \fBgit maintenance run \-\-auto\fR\&. If zero, then the
544 task will not run with the
546 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
547 \fBmaintenance\&.loose\-objects\&.auto\fR\&. The default value is 100\&.
550 maintenance\&.incremental\-repack\&.auto
552 This integer config option controls how often the
553 \fBincremental\-repack\fR
554 task should be run as part of
555 \fBgit maintenance run \-\-auto\fR\&. If zero, then the
556 \fBincremental\-repack\fR
557 task will not run with the
559 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
560 \fBmaintenance\&.incremental\-repack\&.auto\fR\&. The default value is 10\&.
564 Part of the \fBgit\fR(1) suite