Git Tags: Marking Releases
What Are Tags?
Tags are permanent bookmarks in your Git history. They mark specific commits as important — usually releases.
Commits: A ─── B ─── C ─── D ─── E ─── F
↑ ↑
v1.0.0 v2.0.0
Types of Tags
Lightweight Tags
Simple pointers to a commit (like a branch that doesn't move):git tag v1.0.0
Annotated Tags (Recommended)
Include a message, author, and date:git tag -a v1.0.0 -m "First stable release"
Working with Tags
# List all tags
git tagCreate an annotated tag
git tag -a v1.0.0 -m "Release version 1.0.0"Tag a specific older commit
git tag -a v0.9.0 -m "Beta release" abc1234View tag details
git show v1.0.0Push tags to remote
git push origin v1.0.0 # Push one tag
git push origin --tags # Push all tagsDelete a tag
git tag -d v1.0.0 # Local
git push origin :v1.0.0 # Remote
Semantic Versioning
Most projects use Semantic Versioning (SemVer): MAJOR.MINOR.PATCH
| Version Part | When to Increment | Example |
|---|---|---|
| MAJOR | Breaking changes | v1.0.0 → v2.0.0 |
| MINOR | New features (backward compatible) | v1.0.0 → v1.1.0 |
| PATCH | Bug fixes | v1.0.0 → v1.0.1 |
Checking Out Tags
# View code at a specific tag
git checkout v1.0.0Create a branch from a tag
git checkout -b hotfix v1.0.0
Summary
| Command | Purpose |
|---|---|
| <code>git tag v1.0.0</code> | Create lightweight tag |
| <code>git tag -a v1.0.0 -m "msg"</code> | Create annotated tag |
| <code>git tag</code> | List all tags |
| <code>git push origin --tags</code> | Push all tags to remote |
| <code>git show v1.0.0</code> | View tag details |