brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: git maintenance start keeps a big repository fast in the background

Git
~/tips/tip-git-maintenance-start

git maintenance start

Registers the repository for scheduled background upkeep like prefetching and commit-graph updates, so it stays fast.

Big repositories get slow in small ways: status takes a beat longer, fetch drags. Git has a built-in fix that most people never switch on, and I would turn it on for any repository I use daily.

cd ~/code/big-repo
git maintenance start

The command registers the repository for maintenance and sets up a background scheduler that runs git maintenance run --scheduled every hour. Which scheduler depends on your system: systemd user timers on Linux when available (otherwise cron), launchctl on macOS and schtasks on Windows. It needs Git 2.29 or newer.

With the default incremental strategy the commit-graph and a prefetch run hourly, loose objects and incremental repacks run daily, and the heavy gc task stays off. The prefetch downloads new objects into refs/prefetch/, so your next git fetch has less to transfer, and your own branches are left alone.

To check what is registered, run:

git config --global --get-all maintenance.repo

The caveat is that the schedule is per user, not per project, and it only covers repositories you registered. Changing the timing means editing the generated timer or plist, and the docs warn that running git maintenance start again overwrites those files. To stop, use git maintenance stop, and git maintenance unregister drops the current repository from the list.

Further reading: git-maintenance documentation

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link