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

`git log --graph`, `git merge-base` and `git branch --contains` take tens of seconds on a repo with 500k commits.

AdvancedTroubleshootingRepository Health, Size and Performance
Answer

Likely causes → No commit-graph file, so Git parses every commit object to walk history and compute generation numbers. Many loose refs and many packs add more overhead.

Diagnose →

ls .git/objects/info/commit-graph* .git/objects/info/commit-graphs 2>/dev/null
git count-objects -v | grep packs
GIT_TRACE2_PERF=1 git merge-base main feature 2>&1 | tail -5

Fix →

git commit-graph write --reachable --changed-paths   # changed-paths also speeds up "git log -- <path>"
git config fetch.writeCommitGraph true
git pack-refs --all
git multi-pack-index write

Prevent → git maintenance start keeps the commit-graph, multi-pack-index and prefetches up to date on a schedule.

All Git & GitHub questions Roadmap: Git & GitHub

More on Repository Health, Size and Performance