git count-objects: Usage, Options & Common CI Errors
By Daniel Zoghalchali·Latchkey
git count-objects summarizes how many objects and packs your repository is carrying.
Before deciding to gc or repack, count-objects shows whether loose objects have piled up and how much disk the repo uses - a quick health check for CI caches and large repos.
What it does
git count-objects counts the loose (unpacked) objects and their on-disk size; with -v it also reports packed objects, the number of packs, and garbage that gc would remove.
count-objects rarely errors; the gotcha is interpretation. A high "count" of loose objects signals that gc/repack would help, while a large "size-garbage" line means unreachable objects waiting for prune. It reports the current repo only, so submodules and worktrees are counted separately.
Using this in CI
CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.
.github/workflows/ci.yml
- uses:actions/checkout@v4with:fetch-depth:0 # history, tags, and git describe all need this- run:|git rev-parse --is-shallow-repository # expect falsegit rev-parse --abbrev-ref HEAD # prints HEAD when detached
Frequently asked questions
git count-objects: Usage, Options & Common CI Errors?
Before deciding to gc or repack, count-objects shows whether loose objects have piled up and how much disk the repo uses - a quick health check for CI caches and large repos.
What it does?
git count-objects counts the loose (unpacked) objects and their on-disk size; with -v it also reports packed objects, the number of packs, and garbage that gc would remove.
Common errors in CI?
count-objects rarely errors; the gotcha is interpretation. A high "count" of loose objects signals that gc/repack would help, while a large "size-garbage" line means unreachable objects waiting for prune. It reports the current repo only, so submodules and worktrees are counted separately.