git tag Command: Create Tags in CI
git tag marks specific commits with a name, typically a release version.
Release pipelines create tags to freeze a version and list tags to discover the latest release. Annotated tags carry metadata and are preferred for releases.
Common flags
-a <name>- create an annotated tag (stored as a full object with author and message)-m <msg>- supply the tag message (required for -a in non-interactive CI)-l <pattern>/--list- list tags, optionally filtered by a glob--sort=-version:refname- sort tags by version, newest first-d <name>- delete a local tag-f- replace an existing tag of the same name
Example
shell
# Cut an annotated release tag from CI
git tag -a "v${VERSION}" -m "Release v${VERSION}"
git push origin "v${VERSION}"
# Find the latest semver tag
git tag -l 'v*' --sort=-version:refname | head -n1In CI
Always pass -m with -a so tag creation does not block on an editor on a headless runner. Use --sort=-version:refname to find the newest version reliably instead of relying on creation order. Remember to push tags explicitly; a normal push does not send them.
Key takeaways
- Annotated tags (-a -m) are the right choice for releases and carry metadata.
- Supply -m in CI so tag creation never opens an editor.
- Tags are not pushed by a plain git push; push them explicitly.
Related guides
git push Command: Publish Refs in CIgit push uploads commits and tags to a remote. Reference for --tags, --follow-tags, and --force-with-lease as…
git describe Command: Version Strings in CIgit describe builds a human-readable version from tags. Reference for --tags and --always to derive build ver…
git for-each-ref Command in CIgit for-each-ref lists refs with custom formatting. Reference for --sort, --format, and --count to script ove…
git show Command: Inspect Objects in CIgit show displays commits, tags, and file contents at a revision. Reference for printing a commit message or…