The git describe command fails when used with --match or --exact-match options and no tags match the specified pattern or commit. This occurs when trying to find a specific tag that describes the current commit.
The git describe command is used to give a human-readable name to a commit based on the nearest reachable tag. When you use the --exact-match option, git describe will only output if the current commit is tagged exactly. If you use the --match option with a pattern, it will only consider tags matching that glob pattern. This error occurs when git describe cannot find any tags that satisfy your search criteria. With --exact-match, it means the current commit doesn't have a tag pointing directly to it. With --match, it means no tags in your repository match the specified pattern, or none of the matching tags are reachable from the current commit. This is commonly encountered in CI/CD pipelines when trying to determine version numbers from tags, or when attempting to verify that a specific commit has been tagged for release.
First, verify that your repository has tags:
git tag -lIf this returns no output, you have no tags. You'll need to create at least one tag:
git tag v1.0.0If you're using --exact-match, check if the current commit (HEAD) has a tag:
git tag --points-at HEADIf this returns no output, the current commit is not tagged. You can either:
- Switch to a tagged commit
- Create a tag for the current commit: git tag v1.0.1
- Use git describe without --exact-match to find the nearest tag
If using --match, verify that tags matching your pattern exist:
# List all tags matching pattern
git tag -l 'v*'
# Try describe with --match
git describe --match 'v*'Adjust your glob pattern to match your actual tag naming convention. Common patterns:
- v* - matches v1.0.0, v2.1.3, etc.
- release-* - matches release-2024.1, release-2024.2, etc.
- * - matches all tags
In CI/CD environments or after shallow clones, tags may not be present:
# Fetch all tags from remote
git fetch --tags
# Or fetch with full history (unshallow)
git fetch --unshallowFor GitHub Actions, ensure your workflow fetches full history:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all branches and tagsFor GitLab CI, disable shallow cloning in Settings → CI/CD → General Pipelines or use:
variables:
GIT_DEPTH: 0By default, git describe only considers annotated tags. If you have lightweight tags, add the --tags option:
# Consider both annotated and lightweight tags
git describe --tags --match 'v*'To check what type your tags are:
# Annotated tags show detailed info
git show v1.0.0
# Lightweight tags show the commit they point toIf you want git describe to always return something even when no tags match, use --always:
# Returns tag if found, otherwise abbreviated commit hash
git describe --tags --always
# With --match pattern
git describe --match 'v*' --alwaysThis is useful in build scripts where you need some identifier regardless of whether tags exist.
Understanding Tag Reachability
Git describe only considers tags that are reachable by following parent commits from the current commit. If you've created tags on different branches that haven't been merged, they won't be considered. Use git describe --all to consider branches and remote-tracking references as well.
Pattern Matching with --match
The --match option accepts glob(7) patterns, not regular expressions. Multiple --match options can be provided, and a tag matching any pattern will be considered. Use --no-match to clear previously specified patterns.
Tag Preference Order
When multiple tags could describe the same commit:
1. Annotated tags are preferred over lightweight tags
2. Tags with newer dates are preferred over older ones
3. If tied, lexicographic order determines the winner
Performance in Large Repositories
In repositories with many tags, consider using --match to limit the search space. This can significantly improve performance of git describe in CI/CD pipelines.
Versioning Best Practices
For semantic versioning workflows:
- Use annotated tags for releases: git tag -a v1.2.3 -m "Release 1.2.3"
- Push tags explicitly: git push --tags or git push origin v1.2.3
- Establish a consistent naming convention (e.g., v* prefix) and use --match to filter
- In CI/CD, always fetch tags before attempting version determination
warning: BOM detected in file, this may cause issues
UTF-8 Byte Order Mark (BOM) detected in file
fatal: Server does not support --shallow-exclude
Server does not support --shallow-exclude
warning: filtering out blobs larger than limit
Git partial clone filtering large blobs warning
fatal: Server does not support --shallow-since
Server does not support --shallow-since in Git
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server