Version Tagging in Git
What you'll learn: How to create permanent markers in Git that link specific commits to release versions, making it easy to track and retrieve any version of your software.
What Are Git Tags?
Git tags are like bookmarks in a book—they mark specific points in your repository's history that matter. While branches move forward with new commits, tags stay fixed to one commit forever. This makes them perfect for marking release versions like v1.2.0 or v2.0.1.
Lightweight vs Annotated Tags
Git offers two types of tags. Lightweight tags are simple pointers to a commit—just a name. Annotated tags are full Git objects that store the tagger's name, email, date, and a message. For releases, always use annotated tags because they preserve crucial metadata about who released what and when.
Creating Annotated Tags
To create an annotated tag for a release:
git tag -a v1.5.0 -m "Release version 1.5.0 - New payment gateway"
The -a flag makes it annotated, and -m adds your message. This permanently links version v1.5.0 to the current commit's SHA.
To tag a specific commit after the fact:
git tag -a v1.4.9 abc123def -m "Hotfix release 1.4.9"
Pushing and Sharing Tags
Tags aren't pushed automatically with commits. You must push them explicitly:
git push origin v1.5.0 # Push one tag
git push origin --tags # Push all tags
This makes your version history available to the entire team and your CI/CD pipeline.
Viewing and Using Tags
List all tags: git tag
View tag details: git show v1.5.0
Checkout a tagged version: git checkout v1.5.0
Key Takeaway: Annotated Git tags create immutable, documented markers that link semantic versions to specific commits, forming the foundation of traceable release history and enabling quick rollbacks to any previous version.