1GIT-MAINTENANCE(1)                Git Manual                GIT-MAINTENANCE(1)
2
3
4

NAME

6       git-maintenance - Run tasks to optimize Git repository data
7

SYNOPSIS

9       git maintenance run [<options>]
10

DESCRIPTION

12       Run tasks to optimize Git repository data, speeding up other Git
13       commands and reducing storage requirements for the repository.
14
15       Git commands that add repository data, such as git add or git fetch,
16       are optimized for a responsive user experience. These commands do not
17       take time to optimize the Git data, since such optimizations scale with
18       the full size of the repository while these user commands each perform
19       a relatively small action.
20
21       The git maintenance command provides flexibility for how to optimize
22       the Git repository.
23

SUBCOMMANDS

25       register
26           Initialize Git config values so any scheduled maintenance will
27           start running on this repository. This adds the repository to the
28           maintenance.repo config variable in the current user’s global
29           config and enables some recommended configuration values for
30           maintenance.<task>.schedule. The tasks that are enabled are safe
31           for running in the background without disrupting foreground
32           processes.
33
34           The register subcommand will also set the maintenance.strategy
35           config value to incremental, if this value is not previously set.
36           The incremental strategy uses the following schedule for each
37           maintenance task:
38
39gc: disabled.
40
41commit-graph: hourly.
42
43prefetch: hourly.
44
45loose-objects: daily.
46
47incremental-repack: daily.
48
49           git maintenance register will also disable foreground maintenance
50           by setting maintenance.auto = false in the current repository. This
51           config setting will remain after a git maintenance unregister
52           command.
53
54       run
55           Run one or more maintenance tasks. If one or more --task options
56           are specified, then those tasks are run in that order. Otherwise,
57           the tasks are determined by which maintenance.<task>.enabled config
58           options are true. By default, only maintenance.gc.enabled is true.
59
60       start
61           Start running maintenance on the current repository. This performs
62           the same config updates as the register subcommand, then updates
63           the background scheduler to run git maintenance run --scheduled on
64           an hourly basis.
65
66       stop
67           Halt the background maintenance schedule. The current repository is
68           not removed from the list of maintained repositories, in case the
69           background maintenance is restarted later.
70
71       unregister
72           Remove the current repository from background maintenance. This
73           only removes the repository from the configured list. It does not
74           stop the background maintenance processes from running.
75

TASKS

77       commit-graph
78           The commit-graph job updates the commit-graph files incrementally,
79           then verifies that the written data is correct. The incremental
80           write is safe to run alongside concurrent Git processes since it
81           will not expire .graph files that were in the previous
82           commit-graph-chain file. They will be deleted by a later run based
83           on the expiration delay.
84
85       prefetch
86           The prefetch task updates the object directory with the latest
87           objects from all registered remotes. For each remote, a git fetch
88           command is run. The refmap is custom to avoid updating local or
89           remote branches (those in refs/heads or refs/remotes). Instead, the
90           remote refs are stored in refs/prefetch/<remote>/. Also, tags are
91           not updated.
92
93           This is done to avoid disrupting the remote-tracking branches. The
94           end users expect these refs to stay unmoved unless they initiate a
95           fetch. With prefetch task, however, the objects necessary to
96           complete a later real fetch would already be obtained, so the real
97           fetch would go faster. In the ideal case, it will just become an
98           update to a bunch of remote-tracking branches without any object
99           transfer.
100
101       gc
102           Clean up unnecessary files and optimize the local repository. "GC"
103           stands for "garbage collection," but this task performs many
104           smaller tasks. This task can be expensive for large repositories,
105           as it repacks all Git objects into a single pack-file. It can also
106           be disruptive in some situations, as it deletes stale data. See
107           git-gc(1) for more details on garbage collection in Git.
108
109       loose-objects
110           The loose-objects job cleans up loose objects and places them into
111           pack-files. In order to prevent race conditions with concurrent Git
112           commands, it follows a two-step process. First, it deletes any
113           loose objects that already exist in a pack-file; concurrent Git
114           processes will examine the pack-file for the object data instead of
115           the loose object. Second, it creates a new pack-file (starting with
116           "loose-") containing a batch of loose objects. The batch size is
117           limited to 50 thousand objects to prevent the job from taking too
118           long on a repository with many loose objects. The gc task writes
119           unreachable objects as loose objects to be cleaned up by a later
120           step only if they are not re-added to a pack-file; for this reason
121           it is not advisable to enable both the loose-objects and gc tasks
122           at the same time.
123
124       incremental-repack
125           The incremental-repack job repacks the object directory using the
126           multi-pack-index feature. In order to prevent race conditions with
127           concurrent Git commands, it follows a two-step process. First, it
128           calls git multi-pack-index expire to delete pack-files unreferenced
129           by the multi-pack-index file. Second, it calls git multi-pack-index
130           repack to select several small pack-files and repack them into a
131           bigger one, and then update the multi-pack-index entries that refer
132           to the small pack-files to refer to the new pack-file. This
133           prepares those small pack-files for deletion upon the next run of
134           git multi-pack-index expire. The selection of the small pack-files
135           is such that the expected size of the big pack-file is at least the
136           batch size; see the --batch-size option for the repack subcommand
137           in git-multi-pack-index(1). The default batch-size is zero, which
138           is a special case that attempts to repack all pack-files into a
139           single pack-file.
140
141       pack-refs
142           The pack-refs task collects the loose reference files and collects
143           them into a single file. This speeds up operations that need to
144           iterate across many references. See git-pack-refs(1) for more
145           information.
146

OPTIONS

148       --auto
149           When combined with the run subcommand, run maintenance tasks only
150           if certain thresholds are met. For example, the gc task runs when
151           the number of loose objects exceeds the number stored in the
152           gc.auto config setting, or when the number of pack-files exceeds
153           the gc.autoPackLimit config setting. Not compatible with the
154           --schedule option.
155
156       --schedule
157           When combined with the run subcommand, run maintenance tasks only
158           if certain time conditions are met, as specified by the
159           maintenance.<task>.schedule config value for each <task>. This
160           config value specifies a number of seconds since the last time that
161           task ran, according to the maintenance.<task>.lastRun config value.
162           The tasks that are tested are those provided by the --task=<task>
163           option(s) or those with maintenance.<task>.enabled set to true.
164
165       --quiet
166           Do not report progress or other information over stderr.
167
168       --task=<task>
169           If this option is specified one or more times, then only run the
170           specified tasks in the specified order. If no --task=<task>
171           arguments are specified, then only the tasks with
172           maintenance.<task>.enabled configured as true are considered. See
173           the TASKS section for the list of accepted <task> values.
174

TROUBLESHOOTING

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

BACKGROUND MAINTENANCE ON POSIX SYSTEMS

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

BACKGROUND MAINTENANCE ON MACOS SYSTEMS

267       While macOS technically supports cron, using crontab -e requires
268       elevated privileges and the executed process does not have a full user
269       context. Without a full user context, Git and its credential helpers
270       cannot access stored credentials, so some maintenance tasks are not
271       functional.
272
273       Instead, git maintenance start interacts with the launchctl tool, which
274       is the recommended way to schedule timed jobs in macOS. Scheduling
275       maintenance through git maintenance (start|stop) requires some
276       launchctl features available only in macOS 10.11 or later.
277
278       Your user-specific scheduled tasks are stored as XML-formatted .plist
279       files in ~/Library/LaunchAgents/. You can see the currently-registered
280       tasks using the following command:
281
282           $ ls ~/Library/LaunchAgents/org.git-scm.git*
283           org.git-scm.git.daily.plist
284           org.git-scm.git.hourly.plist
285           org.git-scm.git.weekly.plist
286
287       One task is registered for each --schedule=<frequency> option. To
288       inspect how the XML format describes each schedule, open one of these
289       .plist files in an editor and inspect the <array> element following the
290       <key>StartCalendarInterval</key> element.
291
292       git maintenance start will overwrite these files and register the tasks
293       again with launchctl, so any customizations should be done by creating
294       your own .plist files with distinct names. Similarly, the git
295       maintenance stop command will unregister the tasks with launchctl and
296       delete the .plist files.
297
298       To create more advanced customizations to your background tasks, see
299       launchctl.plist(5) for more information.
300

BACKGROUND MAINTENANCE ON WINDOWS SYSTEMS

302       Windows does not support cron and instead has its own system for
303       scheduling background tasks. The git maintenance start command uses the
304       schtasks command to submit tasks to this system. You can inspect all
305       background tasks using the Task Scheduler application. The tasks added
306       by Git have names of the form Git Maintenance (<frequency>). The Task
307       Scheduler GUI has ways to inspect these tasks, but you can also export
308       the tasks to XML files and view the details there.
309
310       Note that since Git is a console application, these background tasks
311       create a console window visible to the current user. This can be
312       changed manually by selecting the "Run whether user is logged in or
313       not" option in Task Scheduler. This change requires a password input,
314       which is why git maintenance start does not select it by default.
315
316       If you want to customize the background tasks, please rename the tasks
317       so future calls to git maintenance (start|stop) do not overwrite your
318       custom tasks.
319

GIT

321       Part of the git(1) suite
322
323
324
325Git 2.31.1                        2021-03-26                GIT-MAINTENANCE(1)
Impressum