git-maintenance
Optimize Git repository performance periodically
TLDR
Register the current repository in the user's list of repositories to daily have maintenance run
Schedule maintenance tasks to run on the current repository every hour
Halt the background maintenance schedule for the current repository
Remove the current repository from the user's maintenance repository list
Run a specific maintenance task on the current repository
SYNOPSIS
git maintenance <command> [<options>] [<directories>…]
PARAMETERS
run
Immediately run one or more maintenance tasks.
--auto
Run only if a task hasn't run recently (default).
--no-auto
Ignore scheduling heuristics; run all tasks.
--dry-run
Print tasks that would run, without executing.
--force
Run even if recently completed.
--quiet
Suppress non-error output.
--scheduler={hourly|daily}
Use specified scheduler for heuristics.
--task=<task>
Include specific task (e.g., gc, prefetch).
--no-task=<task>
Skip specific task.
start
Start maintenance daemon with scheduler.
--daemon
Fork into background (default for start).
stop
Stop the maintenance daemon.
register
Register repository for maintenance scheduling.
--auto
Register with automatic scheduling.
unregister
Remove repository from maintenance scheduling.
config
Get/set maintenance configuration.
DESCRIPTION
git maintenance is a Git command designed to automate and simplify repository maintenance. It performs essential housekeeping tasks like garbage collection (git gc), repacking loose objects, prefetching from remotes, and incremental repacks to keep repositories efficient and space-optimized.
Use git maintenance run for manual execution or git maintenance start to launch a daemon that schedules tasks hourly or daily. It supports registering multiple repositories (~/.git/maintenance/) for background maintenance, reducing manual cron jobs. Tasks run opportunistically to minimize disruption, respecting schedules and recent activity.
Ideal for servers hosting many repos, it improves performance by compressing objects, removing cruft, and pre-fetching data. Avoid on low-resource systems during peak loads.
CAVEATS
Tasks can be CPU/I/O intensive; monitor on shared hosts. Daemon requires write access to ~/.git/. Not for bare repos without config.
SUPPORTED TASKS
gc (garbage collect), loose-objects, prefetch, repack (incremental/full), commit-graph, multi-pack-index.
SCHEDULING
Hourly checks for short tasks; daily for heavy ones like full repack. Configurable via git config maintenance.strategy.
HISTORY
Introduced in Git 2.30 (April 2021) to consolidate scattered maintenance into a unified scheduler, replacing ad-hoc cron scripts for git gc and similar.
SEE ALSO
git-gc(1), git-repack(1), git-fetch(1), git-fsck(1), cron(8)


