'\" t .\" Title: git-maintenance .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author] .\" Generator: DocBook XSL Stylesheets vsnapshot .\" Date: 02/23/2023 .\" Manual: Git Manual .\" Source: Git 2.39.2 .\" Language: English .\" .TH "GIT\-MAINTENANCE" "1" "02/23/2023" "Git 2\&.39\&.2" "Git Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" git-maintenance \- Run tasks to optimize Git repository data .SH "SYNOPSIS" .sp .nf \fIgit maintenance\fR run [] \fIgit maintenance\fR start [\-\-scheduler=] \fIgit maintenance\fR (stop|register|unregister) [] .fi .sp .SH "DESCRIPTION" .sp Run tasks to optimize Git repository data, speeding up other Git commands and reducing storage requirements for the repository\&. .sp 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\&. .sp The \fBgit maintenance\fR command provides flexibility for how to optimize the Git repository\&. .SH "SUBCOMMANDS" .PP run .RS 4 Run one or more maintenance tasks\&. If one or more \fB\-\-task\fR options are specified, then those tasks are run in that order\&. Otherwise, the tasks are determined by which \fBmaintenance\&.\&.enabled\fR config options are true\&. By default, only \fBmaintenance\&.gc\&.enabled\fR is true\&. .RE .PP start .RS 4 Start running maintenance on the current repository\&. This performs the same config updates as the \fBregister\fR subcommand, then updates the background scheduler to run \fBgit maintenance run \-\-scheduled\fR on an hourly basis\&. .RE .PP stop .RS 4 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\&. .RE .PP register .RS 4 Initialize Git config values so any scheduled maintenance will start running on this repository\&. This adds the repository to the \fBmaintenance\&.repo\fR config variable in the current user\(cqs global config, or the config specified by \-\-config\-file option, and enables some recommended configuration values for \fBmaintenance\&.\&.schedule\fR\&. The tasks that are enabled are safe for running in the background without disrupting foreground processes\&. .sp The \fBregister\fR subcommand will also set the \fBmaintenance\&.strategy\fR config value to \fBincremental\fR, if this value is not previously set\&. The \fBincremental\fR strategy uses the following schedule for each maintenance task: .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} \fBgc\fR: disabled\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} \fBcommit\-graph\fR: hourly\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} \fBprefetch\fR: hourly\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} \fBloose\-objects\fR: daily\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} \fBincremental\-repack\fR: daily\&. .RE .sp \fBgit maintenance register\fR will also disable foreground maintenance by setting \fBmaintenance\&.auto = false\fR in the current repository\&. This config setting will remain after a \fBgit maintenance unregister\fR command\&. .RE .PP unregister .RS 4 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\&. .sp The \fBunregister\fR subcommand will report an error if the current repository is not already registered\&. Use the \fB\-\-force\fR option to return success even when the current repository is not registered\&. .RE .SH "TASKS" .PP commit\-graph .RS 4 The \fBcommit\-graph\fR job updates the \fBcommit\-graph\fR 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 \fB\&.graph\fR files that were in the previous \fBcommit\-graph\-chain\fR file\&. They will be deleted by a later run based on the expiration delay\&. .RE .PP prefetch .RS 4 The \fBprefetch\fR task updates the object directory with the latest objects from all registered remotes\&. For each remote, a \fBgit fetch\fR command is run\&. The configured refspec is modified to place all requested refs within \fBrefs/prefetch/\fR\&. Also, tags are not updated\&. .sp 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\&. .RE .PP gc .RS 4 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 \fBgit-gc\fR(1) for more details on garbage collection in Git\&. .RE .PP loose\-objects .RS 4 The \fBloose\-objects\fR 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 \fBgc\fR 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 \fBloose\-objects\fR and \fBgc\fR tasks at the same time\&. .RE .PP incremental\-repack .RS 4 The \fBincremental\-repack\fR job repacks the object directory using the \fBmulti\-pack\-index\fR feature\&. In order to prevent race conditions with concurrent Git commands, it follows a two\-step process\&. First, it calls \fBgit multi\-pack\-index expire\fR to delete pack\-files unreferenced by the \fBmulti\-pack\-index\fR file\&. Second, it calls \fBgit multi\-pack\-index repack\fR to select several small pack\-files and repack them into a bigger one, and then update the \fBmulti\-pack\-index\fR 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 \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 \fB\-\-batch\-size\fR option for the \fBrepack\fR subcommand in \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\&. .RE .PP pack\-refs .RS 4 The \fBpack\-refs\fR 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 \fBgit-pack-refs\fR(1) for more information\&. .RE .SH "OPTIONS" .PP \-\-auto .RS 4 When combined with the \fBrun\fR subcommand, run maintenance tasks only if certain thresholds are met\&. For example, the \fBgc\fR task runs when the number of loose objects exceeds the number stored in the \fBgc\&.auto\fR config setting, or when the number of pack\-files exceeds the \fBgc\&.autoPackLimit\fR config setting\&. Not compatible with the \fB\-\-schedule\fR option\&. .RE .PP \-\-schedule .RS 4 When combined with the \fBrun\fR subcommand, run maintenance tasks only if certain time conditions are met, as specified by the \fBmaintenance\&.\&.schedule\fR config value for each \fB\fR\&. This config value specifies a number of seconds since the last time that task ran, according to the \fBmaintenance\&.\&.lastRun\fR config value\&. The tasks that are tested are those provided by the \fB\-\-task=\fR option(s) or those with \fBmaintenance\&.\&.enabled\fR set to true\&. .RE .PP \-\-quiet .RS 4 Do not report progress or other information over \fBstderr\fR\&. .RE .PP \-\-task= .RS 4 If this option is specified one or more times, then only run the specified tasks in the specified order\&. If no \fB\-\-task=\fR arguments are specified, then only the tasks with \fBmaintenance\&.\&.enabled\fR configured as \fBtrue\fR are considered\&. See the \fITASKS\fR section for the list of accepted \fB\fR values\&. .RE .PP \-\-scheduler=auto|crontab|systemd\-timer|launchctl|schtasks .RS 4 When combined with the \fBstart\fR subcommand, specify the scheduler for running the hourly, daily and weekly executions of \fBgit maintenance run\fR\&. Possible values for \fB\fR are \fBauto\fR, \fBcrontab\fR (POSIX), \fBsystemd\-timer\fR (Linux), \fBlaunchctl\fR (macOS), and \fBschtasks\fR (Windows)\&. When \fBauto\fR is specified, the appropriate platform\-specific scheduler is used; on Linux, \fBsystemd\-timer\fR is used if available, otherwise \fBcrontab\fR\&. Default is \fBauto\fR\&. .RE .SH "TROUBLESHOOTING" .sp 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\&. .sp 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\&. .sp 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\&. .sp 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\&. .sp 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\&. .sp The following sections describe the mechanisms put in place to run background maintenance by \fBgit maintenance start\fR and how to customize them\&. .SH "BACKGROUND MAINTENANCE ON POSIX SYSTEMS" .sp 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: .sp .if n \{\ .RS 4 .\} .nf # BEGIN GIT MAINTENANCE SCHEDULE # The following schedule was created by Git # Any edits made in this region might be # replaced in the future by a Git command\&. 0 1\-23 * * * "//git" \-\-exec\-path="/" for\-each\-repo \-\-config=maintenance\&.repo maintenance run \-\-schedule=hourly 0 0 * * 1\-6 "//git" \-\-exec\-path="/" for\-each\-repo \-\-config=maintenance\&.repo maintenance run \-\-schedule=daily 0 0 * * 0 "//git" \-\-exec\-path="/" for\-each\-repo \-\-config=maintenance\&.repo maintenance run \-\-schedule=weekly # END GIT MAINTENANCE SCHEDULE .fi .if n \{\ .RE .\} .sp .sp 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\&. .sp 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\&. .sp These commands use \fBgit for\-each\-repo \-\-config=maintenance\&.repo\fR to run \fBgit maintenance run \-\-schedule=\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\fR using the \fBmaintenance\&.\&.schedule\fR config options\&. These values are loaded from the global or repository config values\&. .sp 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\&. .SH "BACKGROUND MAINTENANCE ON LINUX SYSTEMD SYSTEMS" .sp 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\&. .sp If user systemd timers are available, they will be used as a replacement of \fBcron\fR\&. .sp 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: .sp .if n \{\ .RS 4 .\} .nf $ systemctl \-\-user list\-timers NEXT LEFT LAST PASSED UNIT ACTIVATES 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 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 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 .fi .if n \{\ .RE .\} .sp .sp One timer is registered for each \fB\-\-schedule=\fR option\&. .sp The definition of the systemd units can be inspected in the following files: .sp .if n \{\ .RS 4 .\} .nf ~/\&.config/systemd/user/git\-maintenance@\&.timer ~/\&.config/systemd/user/git\-maintenance@\&.service ~/\&.config/systemd/user/timers\&.target\&.wants/git\-maintenance@hourly\&.timer ~/\&.config/systemd/user/timers\&.target\&.wants/git\-maintenance@daily\&.timer ~/\&.config/systemd/user/timers\&.target\&.wants/git\-maintenance@weekly\&.timer .fi .if n \{\ .RE .\} .sp .sp \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\&. .sp \fBgit maintenance stop\fR will stop the user systemd timers and delete the above mentioned files\&. .sp For more details, see \fBsystemd\&.timer(5)\fR\&. .SH "BACKGROUND MAINTENANCE ON MACOS SYSTEMS" .sp 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\&. .sp 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\&. .sp 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: .sp .if n \{\ .RS 4 .\} .nf $ ls ~/Library/LaunchAgents/org\&.git\-scm\&.git* org\&.git\-scm\&.git\&.daily\&.plist org\&.git\-scm\&.git\&.hourly\&.plist org\&.git\-scm\&.git\&.weekly\&.plist .fi .if n \{\ .RE .\} .sp .sp One task is registered for each \fB\-\-schedule=\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\fR element following the \fBStartCalendarInterval\fR element\&. .sp \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\&. .sp To create more advanced customizations to your background tasks, see launchctl\&.plist(5) for more information\&. .SH "BACKGROUND MAINTENANCE ON WINDOWS SYSTEMS" .sp 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 ()\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\&. .sp 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\&. .sp 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\&. .SH "CONFIGURATION" .sp 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: .PP maintenance\&.auto .RS 4 This boolean config option controls whether some commands run \fBgit maintenance run \-\-auto\fR after doing their normal work\&. Defaults to true\&. .RE .PP maintenance\&.strategy .RS 4 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 \fBgit maintenance run \-\-schedule=X\fR commands, provided no \fB\-\-task=\fR arguments are provided\&. Further, if a \fBmaintenance\&.\&.schedule\fR config value is set, then that value is used instead of the one provided by \fBmaintenance\&.strategy\fR\&. The possible strategy strings are: .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} \fBnone\fR: This default setting implies no task are run at any schedule\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} \fBincremental\fR: This setting optimizes for performing small maintenance activities that do not delete any data\&. This does not schedule the \fBgc\fR task, but runs the \fBprefetch\fR and \fBcommit\-graph\fR tasks hourly, the \fBloose\-objects\fR and \fBincremental\-repack\fR tasks daily, and the \fBpack\-refs\fR task weekly\&. .RE .RE .PP maintenance\&.\&.enabled .RS 4 This boolean config option controls whether the maintenance task with name \fB\fR is run when no \fB\-\-task\fR option is specified to \fBgit maintenance run\fR\&. These config values are ignored if a \fB\-\-task\fR option exists\&. By default, only \fBmaintenance\&.gc\&.enabled\fR is true\&. .RE .PP maintenance\&.\&.schedule .RS 4 This config option controls whether or not the given \fB\fR runs during a \fBgit maintenance run \-\-schedule=\fR command\&. The value must be one of "hourly", "daily", or "weekly"\&. .RE .PP maintenance\&.commit\-graph\&.auto .RS 4 This integer config option controls how often the \fBcommit\-graph\fR task should be run as part of \fBgit maintenance run \-\-auto\fR\&. If zero, then the \fBcommit\-graph\fR task will not run with the \fB\-\-auto\fR 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 \fBmaintenance\&.commit\-graph\&.auto\fR\&. The default value is 100\&. .RE .PP maintenance\&.loose\-objects\&.auto .RS 4 This integer config option controls how often the \fBloose\-objects\fR task should be run as part of \fBgit maintenance run \-\-auto\fR\&. If zero, then the \fBloose\-objects\fR task will not run with the \fB\-\-auto\fR 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 \fBmaintenance\&.loose\-objects\&.auto\fR\&. The default value is 100\&. .RE .PP maintenance\&.incremental\-repack\&.auto .RS 4 This integer config option controls how often the \fBincremental\-repack\fR task should be run as part of \fBgit maintenance run \-\-auto\fR\&. If zero, then the \fBincremental\-repack\fR task will not run with the \fB\-\-auto\fR 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 \fBmaintenance\&.incremental\-repack\&.auto\fR\&. The default value is 10\&. .RE .SH "GIT" .sp Part of the \fBgit\fR(1) suite