Text of kernel.org › pub › software › scm › git › docs › git-maintenance.html as Styx crawled it on Nov 19, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

git-maintenance(1)

git-maintenance(1) Manual Page NAME git-maintenance - Run tasks to optimize Git repository data SYNOPSIS git maintenance run [<options>] git maintenance start [--scheduler=<scheduler>] git maintenance (stop|register|unregister) [<options>] git maintenance is-needed [<options>] DESCRIPTION Run tasks to optimize Git repository data, speeding up other Git commands and reducing storage requirements for the repository. Git commands that add repository data, such as git add or git fetch , 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. The git maintenance command provides flexibility for how to optimize the Git repository. SUBCOMMANDS run Run 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: gc : disabled. commit-graph : hourly. prefetch : hourly. loose-objects : daily. incremental-repack : daily. 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 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. is-needed Check whether maintenance needs to be run without actually running it. Exits with a 0 status code if maintenance needs to be run, 1 otherwise.

Ideally used with the --auto flag. If one or more --task options are specified, then those tasks are checked 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. TASKS commit-graph The 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.

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. The remote. <name> .skipFetchAll configuration can be used to exclude a particular remote from getting prefetched. 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 defaults to fifty thousand objects to prevent the job from taking too long on a repository with many loose objects. Use the maintenance.loose-objects.batchSize config option to adjust this size, including a value of 0 to remove the limit.

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. reflog-expire The reflog-expire task deletes any entries in the reflog older than the expiry threshold. See git-reflog(1) for more information. rerere-gc The rerere-gc task invokes garbage collection for stale entries in the rerere cache. See git-rerere(1) for more information. worktree-prune The worktree-prune task deletes stale or broken worktrees.

See git-worktree(1) for more information. OPTIONS --auto When 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. When combined with the is-needed subcommand, check if the required thresholds are met without actually running maintenance. --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 va

The rest of this page is on the live site.