Over time a repo accumulates loose objects and stale refs. Maintenance keeps it fast.
Routine maintenance:
git gc — garbage collection: packs loose objects into compressed packfiles and prunes unreachable ones older than two weeks.
git fsck — verify every object's integrity; reports corruption or orphaned commits.
git maintenance start — register a background task (cron / systemd timer) that runs gc, prefetch, and commit-graph updates on a schedule.
git count-objects -vH — show how much loose vs packed storage you have.
Working with huge repos — clone less to start with:
git clone --depth=1 <url> — shallow clone: only the latest commit's tree. Tiny download; git log only sees one commit.
git clone --filter=blob:none <url> — blobless clone: full commit graph, but file contents fetched lazily on checkout. Best for CI runners.
git sparse-checkout set <paths> — only materialize chosen subdirectories on disk. Combine with blobless for monorepo-scale projects.