Introduction
Git shallow clones (--depth 1) download only the latest commit to save time and bandwidth. However, this strips tags, branch history, and commit metadata that many build tools rely on for version detection:
git clone --depth 1 https://github.com/org/repo.git
cd repo
git describe --tags
# fatal: No names found, cannot describe anything.Build tools that use git describe, git tag, or commit counting for version strings fail in CI/CD pipelines.
Symptoms
git describe --tagsfails with "No names found"- Build version shows "0.0.0-unknown" instead of the actual version
git tagreturns empty output- Build tools cannot determine the version from git metadata
- Semantic versioning plugins fail to find version tags
Common Causes
--depth 1clone does not fetch tags by default- CI/CD pipeline uses shallow clone for speed but build needs tag information
--no-tagsflag used during clone- Build tool uses
git describewhich requires tag ancestry - Monorepo versioning depends on tag reachability
Step-by-Step Fix
- 1.Fetch tags after a shallow clone:
- 2.```bash
- 3.git clone --depth 1 https://github.com/org/repo.git
- 4.cd repo
- 5.git fetch --tags --force
- 6.git describe --tags
- 7.# Now works
- 8.
` - 9.Use sufficient depth to include the nearest tag:
- 10.```bash
- 11.# Clone with enough history to reach tags
- 12.git clone --depth 50 https://github.com/org/repo.git
- 13.
` - 14.For CI/CD pipelines, configure proper clone depth. In GitHub Actions:
- 15.```yaml
- 16.steps:
- 17.- uses: actions/checkout@v4
- 18.with:
- 19.fetch-depth: 0 # Full clone with all history and tags
- 20.
` - 21.Or if you need speed but also tags:
- 22.```yaml
- 23.steps:
- 24.- uses: actions/checkout@v4
- 25.with:
- 26.fetch-depth: 0
- 27.fetch-tags: true
- 28.
` - 29.For GitLab CI:
- 30.```yaml
- 31.variables:
- 32.GIT_STRATEGY: clone
- 33.GIT_DEPTH: 0
- 34.
` - 35.Unshallow an existing shallow clone:
- 36.```bash
- 37.git fetch --unshallow
- 38.git fetch --tags
- 39.
` - 40.This converts a shallow clone to a full clone with all history.
Prevention
- Use
fetch-depth: 0(full clone) in CI/CD when version detection is needed - If using shallow clone for speed, always follow with
git fetch --tags - Configure build tools to handle missing git metadata gracefully (fallback to environment variable)
- Use
GIT_DESCRIBE_TAGenvironment variable in CI/CD as an alternative togit describe - Document the minimum clone depth required for your build tools
- Test your build with both shallow and full clones to detect dependencies on git history
- Consider using a version file (
VERSIONorpackage.json) as the single source of truth - For npm packages, use
npm versionwhich updatespackage.jsondirectly