Synopsis
git count-objects [-v] [-H]
Description
The git count-objects command reports how many loose objects and packs the repository has, and how much disk space they consume. With -v, it includes a breakdown of garbage, packs, in-pack objects, and prune-able objects.
In day-to-day use, git count-objects integrates closely with shell aliases, editor plugins, and continuous integration. Power users often add aliases that combine flags they always pass, or wrap the command in scripts that enforce team conventions. Output formatting can be customized via Git config — pretty formats, color schemes, and pager behavior are all tunable. When something goes wrong, the first diagnostic step is usually to re-run the command with GIT_TRACE=1 in the environment, which reveals the underlying plumbing calls. For unusual situations, the --help output (git count-objects --help) opens the full manual page with details on every option, including those rarely used in casual workflows but essential for debugging or scripting at scale.
Understanding how git count-objects interacts with the rest of Git's data model — the object database, the index, refs, and the working tree — pays dividends. Each command operates on some subset of these pieces, and knowing which it touches helps predict outcomes and recover from mistakes. Reading the official Git documentation alongside hands-on practice in a throwaway repository is the fastest way to internalize the nuances. Most production issues with Git stem from one of three causes: surprising default behavior, partial network operations, or rewriting history that was already shared. A working mental model of git count-objects's side effects helps avoid all three.
When to Use
Run git count-objects -v to gauge whether a repo needs git gc: if loose-object count is high or there are many small packs, garbage collection will compact things. CI and ops teams use it for monitoring repo health.
Common Options
| Option | Description |
|---|---|
-v | Verbose breakdown. |
-H, --human-readable | Sizes in KiB/MiB/GiB. |
Examples
git count-objects
# Quick: number of loose objects and their size
git count-objects -vH
# Full breakdown with human-readable sizes
# count: 235 (loose objects)
# size: 5.2 MiB
# in-pack: 18234
# packs: 3
# size-pack: 142.6 MiB
# prune-packable: 12
# garbage: 0
Common Mistakes
Misreading "garbage" — these are corrupt objects, not just unreachable ones. A non-zero garbage count warrants investigation. prune-packable indicates objects present both loose and in packs; running git gc will resolve them.
Related Commands
git gc, git fsck, git repack, git verify-pack