Interview Prep/Git & GitHub/Repository Health, Size and Performance

A long-lived CI workspace `.git` is 9.8 GiB, while a fresh clone of the same repo is 900 MiB.

IntermediateTroubleshootingRepository Health, Size and Performance
Answer

Likely causes → The cached workspace has accumulated every fetched PR ref (refs/remotes/pull/*), deleted branches that were never pruned, old tags, and loose objects from thousands of fetches. Auto-gc is often disabled on runners, so nothing is ever cleaned.

Diagnose →

git count-objects -vH
git for-each-ref | wc -l
git for-each-ref --format='%(refname)' | cut -d/ -f1-3 | sort | uniq -c | sort -rn | head

Fix →

git fetch --prune --prune-tags origin
git for-each-ref --format='%(refname)' refs/remotes/pull | xargs -r -n1 git update-ref -d
git reflog expire --expire=now --all
git gc --prune=now

Or simply delete the workspace and use a fresh shallow clone.

Prevent → Fetch only what the job needs (specific refspec, --depth), set fetch.prune=true, and schedule a weekly cleanup job on persistent runners.

All Git & GitHub questions Roadmap: Git & GitHub

More on Repository Health, Size and Performance