Skip to content
LatchkeyLatchkey home

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

Terminal
git count-objects
git count-objects -v
git count-objects -vH            # human-readable sizes
# decide whether to repack:
git count-objects -v | grep count

Options

FlagWhat it does
-v / --verboseShow packed counts, packs, and garbage
-H / --human-readablePrint 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.

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@v4
  with:
    fetch-depth: 0   # history, tags, and git describe all need this

- run: |
    git rev-parse --is-shallow-repository   # expect false
    git 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.

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card