`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.
More on Repository Health, Size and Performance
`git status` takes 8–15 seconds in a large monorepo.Intermediate`error: The last gc run reported the following. Please correct the root cause and remove .git/gc.log` followed by `warning: There are too many unreachable loose objects; run 'git prune' to remove them.`IntermediateEvery few commands Git prints `Auto packing the repository in background for optimum performance.` and the machine stutters.BeginnerA fresh clone downloads 4 GB, but the checked-out files are only 200 MB.Intermediate`git gc` or `git clone` dies with `fatal: Out of memory, malloc failed (tried to allocate 1073741824 bytes)` or `error: pack-objects died of signal 9`.Advanced`error: unable to create temporary file: No space left on device` followed by `fatal: failed to write object`.Beginner