NAME
git-maintenance - Run tasks to optimize Git repository dataSYNOPSIS
git maintenance run [<options>] git maintenance start [--scheduler=<scheduler>] git maintenance (stop|register|unregister) [<options>]
DESCRIPTION
Run tasks to optimize Git repository data, speeding up other Git commands and reducing storage requirements for the repository.SUBCOMMANDS
runRun one or more maintenance tasks. If one or
more --task options are specified, then those tasks are run in that
order. Otherwise, the tasks are determined by which
maintenance.<task>.enabled config options are true. By default,
only maintenance.gc.enabled is true.
start
Start running maintenance on the current
repository. This performs the same config updates as the register
subcommand, then updates the background scheduler to run git maintenance
run --scheduled on an hourly basis.
stop
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.
register
Initialize Git config values so any scheduled
maintenance will start running on this repository. This adds the repository to
the maintenance.repo config variable in the current user’s
global config, or the config specified by --config-file option, and enables
some recommended configuration values for
maintenance.<task>.schedule. The tasks that are enabled are safe
for running in the background without disrupting foreground processes.
The register subcommand will also set the maintenance.strategy
config value to incremental, if this value is not previously set. The
incremental strategy uses the following schedule for each maintenance
task:
git maintenance register will also disable foreground maintenance by
setting maintenance.auto = false in the current repository. This config
setting will remain after a git maintenance unregister command.
unregister
•gc: disabled.
•commit-graph: hourly.
•prefetch: hourly.
•loose-objects: daily.
•incremental-repack:
daily.
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.
The unregister subcommand will report an error if the current repository
is not already registered. Use the --force option to return success
even when the current repository is not registered.
TASKS
commit-graphThe commit-graph job updates the
commit-graph 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 .graph files that were in the
previous commit-graph-chain file. They will be deleted by a later run
based on the expiration delay.
prefetch
The prefetch task updates the object
directory with the latest objects from all registered remotes. For each
remote, a git fetch command is run. The configured refspec is modified
to place all requested refs within refs/prefetch/. Also, tags are not
updated.
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.
gc
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
git-gc(1) for more details on garbage collection in Git.
loose-objects
The loose-objects 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 gc 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 loose-objects
and gc tasks at the same time.
incremental-repack
The incremental-repack job repacks the
object directory using the multi-pack-index feature. In order to
prevent race conditions with concurrent Git commands, it follows a two-step
process. First, it calls git multi-pack-index expire to delete
pack-files unreferenced by the multi-pack-index file. Second, it calls
git multi-pack-index repack to select several small pack-files and
repack them into a bigger one, and then update the multi-pack-index
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 git
multi-pack-index expire. 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 --batch-size option for the repack subcommand in
git-multi-pack-index(1). The default batch-size is zero, which is a
special case that attempts to repack all pack-files into a single
pack-file.
pack-refs
The pack-refs 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
git-pack-refs(1) for more information.
OPTIONS
--autoWhen combined with the run subcommand,
run maintenance tasks only if certain thresholds are met. For example, the
gc task runs when the number of loose objects exceeds the number stored
in the gc.auto config setting, or when the number of pack-files exceeds
the gc.autoPackLimit config setting. Not compatible with the
--schedule option.
--schedule
When combined with the run subcommand,
run maintenance tasks only if certain time conditions are met, as specified by
the maintenance.<task>.schedule config value for each
<task>. This config value specifies a number of seconds since the
last time that task ran, according to the
maintenance.<task>.lastRun config value. The tasks that are
tested are those provided by the --task=<task> option(s) or those
with maintenance.<task>.enabled set to true.
--quiet
Do not report progress or other information
over stderr.
--task=<task>
If this option is specified one or more times,
then only run the specified tasks in the specified order. If no
--task=<task> arguments are specified, then only the tasks with
maintenance.<task>.enabled configured as true are
considered. See the TASKS section for the list of accepted
<task> values.
--scheduler=auto|crontab|systemd-timer|launchctl|schtasks
When combined with the start
subcommand, specify the scheduler for running the hourly, daily and weekly
executions of git maintenance run. Possible values for
<scheduler> are auto, crontab (POSIX),
systemd-timer (Linux), launchctl (macOS), and schtasks
(Windows). When auto is specified, the appropriate platform-specific
scheduler is used; on Linux, systemd-timer is used if available,
otherwise crontab. Default is auto.
TROUBLESHOOTING
The git maintenance 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.BACKGROUND MAINTENANCE ON POSIX SYSTEMS
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 crontab -l. The schedule written by git maintenance start is similar to this:# 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 * * * "/<path>/git" --exec-path="/<path>" for-each-repo --config=maintenance.repo maintenance run --schedule=hourly 0 0 * * 1-6 "/<path>/git" --exec-path="/<path>" for-each-repo --config=maintenance.repo maintenance run --schedule=daily 0 0 * * 0 "/<path>/git" --exec-path="/<path>" for-each-repo --config=maintenance.repo maintenance run --schedule=weekly # END GIT MAINTENANCE SCHEDULE
BACKGROUND MAINTENANCE ON LINUX SYSTEMD SYSTEMS
While Linux supports cron, depending on the distribution, cron may be an optional package not necessarily installed. On modern Linux distributions, systemd timers are superseding it.$ 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 [email protected] [email protected] Fri 2021-04-30 00:00:00 CEST 5h 42min left Thu 2021-04-29 00:00:11 CEST 18h ago [email protected] [email protected] Mon 2021-05-03 00:00:00 CEST 3 days left Mon 2021-04-26 00:00:11 CEST 3 days ago [email protected] [email protected]
~/.config/systemd/user/[email protected] ~/.config/systemd/user/[email protected] ~/.config/systemd/user/timers.target.wants/[email protected] ~/.config/systemd/user/timers.target.wants/[email protected] ~/.config/systemd/user/timers.target.wants/[email protected]
BACKGROUND MAINTENANCE ON MACOS SYSTEMS
While macOS technically supports cron, using crontab -e 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.$ 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
BACKGROUND MAINTENANCE ON WINDOWS SYSTEMS
Windows does not support cron and instead has its own system for scheduling background tasks. The git maintenance start command uses the schtasks 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 Git Maintenance (<frequency>). 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.CONFIGURATION
Everything below this line in this section is selectively included from the git-config(1) documentation. The content is the same as what’s found there: maintenance.autoThis boolean config option controls whether
some commands run git maintenance run --auto after doing their normal
work. Defaults to true.
maintenance.strategy
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 git maintenance run
--schedule=X commands, provided no --task=<task> arguments
are provided. Further, if a maintenance.<task>.schedule config
value is set, then that value is used instead of the one provided by
maintenance.strategy. The possible strategy strings are:
maintenance.<task>.enabled
•none: This default setting
implies no task are run at any schedule.
•incremental: This setting
optimizes for performing small maintenance activities that do not delete any
data. This does not schedule the gc task, but runs the prefetch
and commit-graph tasks hourly, the loose-objects and
incremental-repack tasks daily, and the pack-refs task
weekly.
This boolean config option controls whether
the maintenance task with name <task> is run when no
--task option is specified to git maintenance run. These config
values are ignored if a --task option exists. By default, only
maintenance.gc.enabled is true.
maintenance.<task>.schedule
This config option controls whether or not the
given <task> runs during a git maintenance run
--schedule=<frequency> command. The value must be one of
"hourly", "daily", or "weekly".
maintenance.commit-graph.auto
This integer config option controls how often
the commit-graph task should be run as part of git maintenance run
--auto. If zero, then the commit-graph task will not run with the
--auto 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 maintenance.commit-graph.auto. The default value is 100.
maintenance.loose-objects.auto
This integer config option controls how often
the loose-objects task should be run as part of git maintenance run
--auto. If zero, then the loose-objects task will not run with the
--auto 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 maintenance.loose-objects.auto.
The default value is 100.
maintenance.incremental-repack.auto
This integer config option controls how often
the incremental-repack task should be run as part of git maintenance
run --auto. If zero, then the incremental-repack task will not run
with the --auto 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
maintenance.incremental-repack.auto. The default value is 10.
GIT
Part of the git(1) suite02/28/2023 | Git 2.39.2 |