git count-objects: Usage, Options & Common CI Errors
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.
Common usage
git count-objects
git count-objects -v
git count-objects -vH # human-readable sizes
# decide whether to repack:
git count-objects -v | grep countOptions
| Flag | What it does |
|---|---|
| -v / --verbose | Show packed counts, packs, and garbage |
| -H / --human-readable | Print sizes in KiB/MiB/GiB |
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.