Enable Automatic Maintenance in 30 Seconds
Don’t wait until git status takes long enough to brew a cup of coffee before looking to boost productivity. If you’re managing a years-old project with a .git folder weighing several GBs, or need to remove large files from repository history, let Git clean up the mess itself. Just run a single command in the root directory:
git maintenance start
This command is incredibly powerful because it will:
- Add the repository to Git’s “special care” list.
- Automatically set up
crontab(macOS/Linux) orTask Scheduler(Windows) to run background cleanup tasks.
Want to know if Git has actually “scheduled the appointment”? Run this command to check:
git maintenance status
Why Large Projects Must Use This Command
In fact, on a Monorepo project I once worked on, the .git file had bloated to 15GB. Each git fetch took nearly 3 minutes—extremely frustrating. After enabling maintenance, this time dropped to about 30 seconds.
Normally, the git gc (garbage collection) mechanism only runs when the amount of junk files exceeds a certain threshold. The problem is, it often chooses the exact moment you’re rushing to push code to pop up and freeze your terminal. git maintenance (available since Git 2.29) solves this completely by breaking down heavy tasks and running them during idle times.
Highlighting the “Golden” Background Tasks
When you enable this mode, Git quietly performs the following three important tasks:
1. Prefetch (Runs Hourly)
Instead of waiting for you to run a command, Git automatically downloads new objects from the server into a buffer (refs/prefetch/). When you actually run git fetch, the data is already local. The speed is then almost instantaneous.
2. Commit-graph (Runs Hourly)
This is the “map” that helps Git traverse commit history faster. Without it, tools like GitKraken or the git log --graph command have to scan all objects, which is CPU-intensive. With a commit-graph, displaying branches becomes much smoother.
3. Loose-objects (Runs Daily)
It gathers loose files into compressed packfiles. This not only frees up disk space but also significantly speeds up file read/write operations.
# Run manually to experience the speed
git maintenance run --task=commit-graph
Customizing for “Hardcore” Needs
The default configuration is usually enough, but sometimes you need deeper control via the .config file.
Disabling Automatic Fetch
If you’re concerned about bandwidth or security when Git connects to the server on its own, you can disable the prefetch task specifically:
git config maintenance.prefetch.enabled false
git config maintenance.commit-graph.enabled true
Thorough Cleanup with Incremental Repack
For repositories containing many binary files (like images or videos), the incremental-repack task combines small data packages into larger ones to optimize the index. You can force it to run with:
git maintenance run --task=incremental-repack
A Few “Hard-won” Lessons After 6 Months
Deploying this for the whole team isn’t difficult, but keep a few things in mind:
- No need to worry about lag: These tasks run with the lowest priority. If you’re rendering video or gaming, the OS will automatically make Git wait in line.
- Windows Errors: Some company machines have restricted
Task Schedulerpermissions. If thestartcommand returns an error, you’ll need to ask IT for permissions or add the task manually. - A Lifesaver for CI/CD: For servers running Jenkins or GitLab Runner, enabling maintenance helps avoid “Disk full” errors caused by long-term accumulation of junk data.
In short, if you notice Git starting to feel sluggish, don’t rush to delete the repo and clone it again. Try git maintenance first as part of a practical git workflow. If you want to cancel it because the project has ended, just type:
git maintenance stop
This command will clear all scheduled tasks, returning your system to its original state.

