G
GuideDevOps
Lesson 11 of 18

Git Tags & Releases

Part of the Git & Version Control tutorial series.

What are Tags?

Tags are references to specific commits, typically used for marking releases or important milestones.

Tags vs. Branches

ItemTagBranch
PurposeMark point in timeActive development
MovesNever (immutable)Advances with commits
UseReleases, milestonesOngoing work

Creating Tags

Lightweight Tags

Simple reference to a commit (no metadata):

# Create at current commit
git tag v1.0.0
 
# Create at specific commit
git tag v1.0.0 abc1234

Annotated Tags

Include metadata (author, date, message):

git tag -a v1.0.0 -m "Release version 1.0.0"
 
# With signing (GPG)
git tag -s v1.0.0 -m "Release version 1.0.0"
 
# View details
git show v1.0.0

Annotated Recommended for Releases

# Release tag with notes
git tag -a v2.0.0 -m "Major release: API redesign, performance improvements"
 
# Then push
git push origin v2.0.0

Viewing Tags

List All Tags

git tag
# v0.9.0
# v1.0.0
# v1.1.0
 
# More details
git tag -n3  # Shows 3 lines of message

Search Tags

# Find tags matching pattern
git tag -l "v1.*"
# v1.0.0
# v1.1.0
# v1.2.0
 
git tag -l "release*"

Tag Information

# Show tag details
git show v1.0.0
 
# Just see commit
git rev-list -n 1 v1.0.0

Common Tagging Patterns

Semantic Versioning

# MAJOR.MINOR.PATCH
git tag v1.0.0    # Major release
git tag v1.1.0    # Minor (feature) release
git tag v1.0.1    # Patch (bugfix) release
 
# Pre-release versions
git tag v2.0.0-beta.1
git tag v2.0.0-rc.1

Release Process

# Create release tag
git tag -a v1.2.0 -m "Version 1.2.0: Bug fixes and performance"
 
# Push tag to remote
git push origin v1.2.0
 
# Or push all tags
git push origin --tags

Checking Out Tags

View Code at Tag

# See files as they were at tag
git checkout v1.0.0
 
# This puts you in "detached HEAD" state
# You're at a specific commit, not on a branch
 
# To make changes, create a branch
git switch -c bugfix-for-1.0

Create Release Branch

# For maintenance fixes on released version
git checkout -b release-1.0 v1.0.0
 
# Make fixes
git add fixed-file.ts
git commit -m "Fix bug in 1.0"
 
# Push release branch
git push origin release-1.0

Deleting and Updating

Delete Tag

# Delete local tag
git tag -d v1.0.0
 
# Delete remote tag
git push origin --delete v1.0.0

Rename Tag

# Create new tag at same commit
git tag v1.0.0-new v1.0.0
 
# Delete old tag
git tag -d v1.0.0
git push origin --delete v1.0.0
 
# Push new
git push origin v1.0.0-new

Practical Workflows

Tagging Current Release

# Make last commit for release
git commit -m "Bump version to 1.2.0"
 
# Create tag
git tag -a v1.2.0 -m "Release 1.2.0"
 
# Push both
git push origin main
git push origin v1.2.0

See Commits Since Last Release

# Compare current to last tag
git log v1.0.0..HEAD --oneline
 
# Line count changed
git diff v1.0.0 --stat

Find What Version Has a Commit

# Which tags include this commit?
git tag --contains abc1234
 
# What's the closest tag to current?
git describe
# v1.2.0-45-gacf20f3 (45 commits after v1.2.0)

Release Checklist

# Ensure all tests pass
npm test
 
# Update version number
# Update CHANGELOG
 
# Create tag
git tag -a v2.0.0 -m "Version 2.0.0: See CHANGELOG for details"
 
# Push everything
git push origin main
git push origin v2.0.0
 
# Create GitHub release (UI-based)
# Attach binaries if building

Comparing Releases

# What changed between releases
git diff v1.0.0 v1.1.0
 
# Create changelog
git log v1.0.0..v1.1.0 --oneline > CHANGELOG.md
 
# Files changed
git diff v1.0.0 v1.1.0 --name-only

Tips

✓ Use annotated tags for releases (semantic versioning)
✓ Lightweight tags for personal markers
✓ Push tags with release: git push origin v1.0.0
✓ Use tags in CI/CD to trigger builds
✓ Create release notes when tagging
✓ Consistent naming convention (v1.2.3)
✓ Tag before deployment to mark production state