← 返回命令列表

Linux command

git-maintenance 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Start background maintenance

git maintenance start

Run all enabled maintenance tasks

git maintenance run

Run a specific task

git maintenance run --task=[prefetch]

Run tasks only if scheduled thresholds are met

git maintenance run --schedule

Stop background maintenance

git maintenance stop

Register repository

git maintenance register

Unregister repository

git maintenance unregister

说明

git maintenance manages repository maintenance tasks automatically. It handles garbage collection, commit graph updates, prefetch, and incremental repack either on-demand or through scheduled background jobs. Background maintenance improves repository performance over time without manual intervention. The `start` subcommand registers the repository and sets up a system scheduler (crontab, systemd, launchctl, or schtasks depending on platform) to run tasks periodically. The `register` subcommand configures recommended task schedules and sets `maintenance.strategy = incremental` while disabling foreground auto-gc. ## Tasks - gc — Full garbage collection; repacks all objects into a single pack-file. Expensive. - prefetch — Fetches objects from all remotes into `refs/prefetch/` without updating remote-tracking branches. - commit-graph — Incrementally updates commit-graph files for faster graph traversal. - loose-objects — Packs loose objects into pack-files in batches (default batch: 50,000). - incremental-repack — Repacks small pack-files using the multi-pack-index. - pack-refs — Consolidates loose ref files into a single packed-refs file. - reflog-expire — Deletes reflog entries older than the expiry threshold. - rerere-gc — Cleans stale entries from the rerere cache. - worktree-prune — Removes stale or broken worktree records.

参数

run
Run one or more maintenance tasks immediately.
start
Enable background maintenance and schedule hourly runs via the system scheduler.
stop
Disable background maintenance schedule.
register
Add the repository to the global maintenance list and apply recommended task schedules.
unregister
Remove the repository from the global maintenance list.
is-needed
Exit 0 if maintenance tasks need to run, 1 otherwise.
--task _TASK_
Specific task to run. May be repeated. Valid tasks: gc, prefetch, commit-graph, loose-objects, incremental-repack, pack-refs, reflog-expire, rerere-gc, worktree-prune.
--schedule
Only run tasks whose scheduled time threshold has been met.
--auto
Only run tasks if their auto thresholds are met (e.g. gc.auto loose object count).
--quiet
Suppress progress output to stderr.
--scheduler _SCHEDULER_
Background scheduler to use with start: auto, crontab, systemd-timer, launchctl, schtasks (default: auto).
--force
Used with unregister; suppress error if the repository is not registered.
--help
Display help information.

FAQ

What is the git-maintenance command used for?

git maintenance manages repository maintenance tasks automatically. It handles garbage collection, commit graph updates, prefetch, and incremental repack either on-demand or through scheduled background jobs. Background maintenance improves repository performance over time without manual intervention. The `start` subcommand registers the repository and sets up a system scheduler (crontab, systemd, launchctl, or schtasks depending on platform) to run tasks periodically. The `register` subcommand configures recommended task schedules and sets `maintenance.strategy = incremental` while disabling foreground auto-gc. ## Tasks - gc — Full garbage collection; repacks all objects into a single pack-file. Expensive. - prefetch — Fetches objects from all remotes into `refs/prefetch/` without updating remote-tracking branches. - commit-graph — Incrementally updates commit-graph files for faster graph traversal. - loose-objects — Packs loose objects into pack-files in batches (default batch: 50,000). - incremental-repack — Repacks small pack-files using the multi-pack-index. - pack-refs — Consolidates loose ref files into a single packed-refs file. - reflog-expire — Deletes reflog entries older than the expiry threshold. - rerere-gc — Cleans stale entries from the rerere cache. - worktree-prune — Removes stale or broken worktree records.

How do I run a basic git-maintenance example?

Run `git maintenance start` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does run do in git-maintenance?

Run one or more maintenance tasks immediately.