Video in progress
The repo has grown: `git status` takes 6 seconds and a clone takes 15 minutes. How do you diagnose it, and what do you tune?
First I measure what is slow: the file count (working tree), the history size, or big binaries. Then I pick the right tool: fsmonitor and the untracked cache, sparse-checkout, partial clone, and git maintenance with a commit-graph and multi-pack-index.
📖 Answer
Diagnosis:
git count-objects -vH # size of objects and packs
git ls-files | wc -l # number of files in the working tree
GIT_TRACE_PERFORMANCE=1 git status # where the time goes
git rev-list --objects --all | git cat-file --batch-check='%(objectsize) %(rest)' | sort -n | tail -20
The last command shows the biggest files in the history. Often it turns out to be a .jar, a dump or a video that someone committed.
Depending on the cause:
- Many files, slow
status:git config core.fsmonitor true(the built-in daemon in Git 2.37+, on macOS/Windows),core.untrackedCache true,feature.manyFiles true; - Parts nobody needs:
git sparse-checkout set --cone services/order libs/common, so a developer gets only their own part; - Big history:
--filter=blob:nonefor developers, a shallow clone for CI; - Object storage:
git maintenance startruns a commit-graph, prefetch and incremental repack in the background.git log --graphand merge-base computations speed up noticeably; - Big binaries: moving them to LFS or cleaning them out of the history. That is an organizational decision, because the hashes change.
The IDE matters too: if IntelliJ indexes folders such as target/ and node_modules/, it is the IDE that is slow, not Git. That is another reason a correct .gitignore matters.
Sign up to mark studied questions and save your progress.