`git status` takes 8–15 seconds in a large monorepo.
IntermediateTroubleshootingRepository Health, Size and Performance
Answer
Likely causes → Git is lstat()-ing hundreds of thousands of tracked files and walking huge untracked directories (node_modules, build output) on every call. Antivirus scanning on Windows makes it worse.
Diagnose →
GIT_TRACE2_PERF=1 git status 2>&1 | grep -E 'read_directory|refresh_index|preload'
git ls-files | wc -l
git status --untracked-files=no # if this is fast, untracked scanning is the cost
Fix → Turn on the built-in file system monitor and caches:
git config core.fsmonitor true # builtin daemon on macOS/Windows (Git 2.37+)
git config core.untrackedCache true
git config feature.manyFiles true # index v4 + untracked cache
git update-index --index-version 4
On Linux, use Watchman with the fsmonitor-watchman hook, or reduce the tree with sparse checkout. scalar register applies all of this in one go.
Prevent → Make ignored build dirs actually ignored, and ship a repo bootstrap script that sets these configs.
More on Repository Health, Size and Performance
`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`git fsck` prints dozens of `dangling commit ...` and `dangling blob ...` lines. Is the repo broken?Beginner