Git Tags
Git Tags
Section titled “Git Tags”Tags mark specific commits as significant — typically used for releases. Unlike branches, tags don’t move as new commits are added.
Tag Types
Section titled “Tag Types”| Type | Description |
|---|---|
| Lightweight | Just a name pointing to a commit — like a branch that doesn’t move |
| Annotated | Full object with tagger, date, message, and optionally a GPG signature |
Use annotated tags for releases — they contain metadata and show up in git describe.
Creating Tags
Section titled “Creating Tags”# Annotated tag (recommended for releases)git tag -a v1.2.0 -m "Release version 1.2.0"
# Annotated tag on a specific commitgit tag -a v1.1.5 abc1234 -m "Hotfix 1.1.5"
# Lightweight tag (no metadata)git tag v1.2.0Viewing Tags
Section titled “Viewing Tags”# List all tagsgit tag
# Filter by patterngit tag -l "v1.*"
# Show tag detailsgit show v1.2.0
# Show only tag names (for scripting)git tag -lPushing Tags
Section titled “Pushing Tags”Tags are not pushed automatically:
# Push a specific taggit push origin v1.2.0
# Push all tagsgit push origin --tags
# Push annotated tags only (not lightweight)git push origin --follow-tagsDeleting Tags
Section titled “Deleting Tags”# Delete locallygit tag -d v1.2.0-rc1
# Delete from remotegit push origin --delete v1.2.0-rc1git push origin :refs/tags/v1.2.0-rc1 # equivalentChecking Out a Tag
Section titled “Checking Out a Tag”Tags put you in “detached HEAD” state — you’re not on a branch:
git checkout v1.2.0# HEAD is now at abc1234... Release version 1.2.0# (detached HEAD state)To work from a tag, create a branch:
git checkout -b hotfix/v1.2.1 v1.2.0Semantic Versioning
Section titled “Semantic Versioning”The widely adopted MAJOR.MINOR.PATCH convention:
MAJOR — breaking changesMINOR — new backwards-compatible featuresPATCH — backwards-compatible bug fixes
Pre-release: v1.2.0-alpha.1, v1.2.0-beta.2, v1.2.0-rc.1Build metadata: v1.2.0+build.20250124# Current releasegit tag -a v1.2.0 -m "Add OAuth support"
# Bug fixgit tag -a v1.2.1 -m "Fix session expiry bug"
# New feature (backwards compatible)git tag -a v1.3.0 -m "Add dark mode"
# Breaking changegit tag -a v2.0.0 -m "Redesign API — remove deprecated endpoints"git describe
Section titled “git describe”Find the most recent tag reachable from a commit:
git describe# v1.2.0-3-gabc1234# = tag v1.2.0, 3 commits ahead, current commit is abc1234Useful for generating version strings in CI/CD builds.
GitHub Releases
Section titled “GitHub Releases”Tags integrate with GitHub Releases:
# Tag and pushgit tag -a v1.2.0 -m "Release 1.2.0"git push origin v1.2.0Then on GitHub: go to the tag → “Create release” → add release notes and attach build artifacts.
Using GitHub CLI:
gh release create v1.2.0 --title "Version 1.2.0" --notes "Bug fixes and improvements"gh release create v1.2.0 ./dist/my-app-linux-amd64 ./dist/my-app-windows-amd64.exeAutomating Tags in CI/CD
Section titled “Automating Tags in CI/CD”# GitHub Actions — tag and release on push to main- name: Bump version and create tag uses: mathieudutour/github-tag-action@v6.1 with: github_token: ${{ secrets.GITHUB_TOKEN }} default_bump: patchOr trigger a build from a tag push:
on: push: tags: - 'v*'