Back to lessons

Git GC & Repository Maintenance

Keep your Git repository healthy with garbage collection, fsck, and pruning.

Step 1 of 617%

Over time, Git repositories accumulate loose objects, unnecessary data, and fragmentation. Regular maintenance — using git gc, git fsck, and git prune — keeps your repository performant and healthy.

Git's internal object storage is extremely efficient, but it's not self-cleaning. When you create branches, amend commits, or rebase, Git doesn't immediately delete the old objects — they remain in the object database as 'dangling' or 'unreachable' objects. Over months of active development, these can accumulate to hundreds of megabytes of wasted space. Maintenance commands are Git's housekeeping tools: gc compresses and cleans up, fsck validates integrity, and prune removes unreachable objects permanently.
1 / 6