# git count-objects: Usage, Options & Common CI Errors

> git count-objects reports how many loose objects and packs a repo holds and their disk size. Reference for -v, -H, and spotting bloat before gc in CI.

Source: https://latchkey.dev/learn/command-reference/git-count-objects  
Updated: 2026-06-25

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

| 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.

## 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
```

> `git rev-parse --abbrev-ref HEAD` returns the literal string `HEAD` on a detached checkout rather than a branch name. On GitHub Actions read `github.ref_name` instead; the git command cannot know what it was checked out for.

## FAQ

### 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.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
