Learning center

The CI build says version 0.0.0: the checkout fetched no tags

A build that stamps its version with git describe needs the tag in the clone. The default actions/checkout fetches one commit without tags. Then git describe fails, and a script that falls back to a placeholder or to --always keeps going. Before you trust a version string from CI, find the step that computed it and check that the tag was in the clone. Better, make the build fail when it is not.

Why the tag is missing#

The checkout action fetches "a single commit by default", and its fetch-depth input defaults to 1. Its fetch-tags input defaults to false. Setting fetch-depth: 0 fetches "all history for all branches and tags". actions/checkout

git describe names a commit by the nearest tag reachable from it. A clone of one commit without tags has nothing to describe from. Without --tags, it also considers only annotated tags. git-describe

Fixture: three ways the version comes out#

Git 2.43.0. A repository has an annotated tag v1.4.0 two commits behind main. A depth-1 clone of main:

$ git -C origin describe --tags
v1.4.0-2-g7aace73
$ git -C shallow describe --tags
fatal: No names found, cannot describe anything.
exit 128
$ git -C shallow describe --tags --always
7aace73
exit 0
$ git -C shallow rev-parse --is-shallow-repository
true
$ VERSION=$(git -C shallow describe --tags 2>/dev/null || echo 0.0.0-unknown); echo $VERSION
0.0.0-unknown
$ git -C shallow fetch -q --unshallow --tags && git -C shallow describe --tags
v1.4.0-2-g7aace73

The plain command fails loudly. The other two exit 0 with a version that names no release. --always is documented as "Show uniquely abbreviated commit object as fallback", so a bare hash in the version field means the fallback was used.

A second fixture checks out the tagged commit itself with git fetch --no-tags --depth=1 origin +SHA:refs/remotes/origin/main, the refspec the checkout action builds for a branch push. git describe --tags again failed with No names found, although the commit carries v1.5.0. Fetching +refs/tags/*:refs/tags/* made it print v1.5.0. A one-commit checkout does not get the tag even when that commit has one.

Fetch what the version step needs#

- uses: actions/checkout@v7
  with:
    fetch-depth: 0
- run: |
    test "$(git rev-parse --is-shallow-repository)" = false
    VERSION=$(git describe --tags --match 'v*')

fetch-depth: 0 costs a full history fetch. Drop the fallback: without || echo, a missing tag stops the job at the version step and never ships as 0.0.0. On a tag push, the same source adds that tag's refspec, so the pushed tag is in the clone. There you can also take the version from GITHUB_REF_NAME, the tag's short name, and skip git describe.

Read a version string as evidence#

Version you seeWhat produced itWhat settles it
v1.4.0-2-g7aace73Tag found, two commits after itgit rev-parse v1.4.0 in a full clone
7aace73 alone--always fallback, no tag in the cloneThe checkout's depth and tags
0.0.0, unknown, devA script fallbackThe build log of the version step
v1.3.9-40-g…An older annotated tag; the newer tag is lightweight or not an ancestorgit cat-file -t on the newer tag, and git merge-base --is-ancestor

The last row is the dangerous one, because the string looks plausible. A lightweight tag does not count without --tags, and a tag on a commit that the build does not descend from, such as a tag on a release branch, is not reachable. Either way, describe reaches back to an older annotated tag and the string still has the right shape. Compare the tag and commit in the version string with the release you meant to build.

Before you rely on a tag at all, see protecting release tags. For tags that name a tag object instead of a commit, read peeling an annotated tag.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading