Skip to content
Latchkey

git rev-list --count: Usage, Options & Common CI Errors

git rev-list --count prints how many commits a range contains.

Need to know how many commits a branch is ahead, or how many landed since a tag? rev-list --count gives a single number that is easy to compare in CI conditions.

What it does

git rev-list --count walks the requested revision range and prints only the count of matching commits, instead of listing their SHAs.

Common usage

Terminal
git rev-list --count HEAD
git rev-list --count main..feature        # commits ahead of main
git rev-list --count --left-right main...feature
git rev-list --count v1.0.0..HEAD         # commits since a tag

Options

FlagWhat it does
--countPrint the number, not the list
<a>..<b>Commits in b not in a
<a>...<b>Symmetric difference
--left-rightWith ..., split counts per side
--no-mergesExclude merge commits

Common errors in CI

A two-dot range (main..feature) needs both refs present; on a shallow clone the merge base may be missing and the count is wrong or errors. Use fetch-depth: 0. Note .. (asymmetric) and ... (symmetric) differ - mixing them up gives surprising ahead/behind numbers.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →