The Hook (The "Byte-Sized" Intro)
Branches move. Commits pile up. But sometimes you need to say: "This exact commit is version 1.0." That's a tag — a permanent bookmark in your Git history. Unlike branches, tags don't move when you make new commits. They stay fixed, pointing to the exact same commit forever. That's why every release, every deploy, every stable milestone uses a tag.
📖 What Are Tags?
A Git tag is a named reference that points to a specific commit. Unlike branches (which advance with each new commit), tags are fixed — they always point to the same commit.
Conceptual Clarity
Two types of tags:
| Type | What It Stores | Use Case |
|---|---|---|
| Lightweight | Just a name → commit pointer | Quick local bookmarks |
| Annotated | Name + author + date + message + optional GPG signature | Releases, production milestones |
Tags vs Branches:
| Feature | Tag | Branch |
|---|---|---|
| Moves with new commits? | ❌ No — fixed forever | ✅ Yes — advances |
| Has metadata? | Annotated: ✅ | ❌ Just a pointer |
| Purpose | Mark a point in time | Active development |
| Example | v1.0.0, v2.3.1 | main, feature/login |
Real-Life Analogy
If Git history is a book, branches are bookmarks that move as you read. Tags are like highlighted passages — they mark something important and stay exactly where they are, even as the book gets more pages.
Visual Architecture
Why It Matters
- Release tracking: Every software release should be tagged for traceability.
- Deployment: CI/CD systems use tags to trigger production deployments.
- Rollback: Tags make it trivial to return to a known-good version.
- Communication:
v2.1.0is clearer thanabc123defin team discussions.
Code
# ─── Create a lightweight tag ───
git tag v1.0.0
# Points to current HEAD
# ─── Create an annotated tag (recommended for releases) ───
git tag -a v1.0.0 -m "First stable release"
# Stores: tagger name, email, date, message
# ─── Tag a specific commit ───
git tag -a v0.9.0 abc1234 -m "Beta release"
# ─── View a tag's details ───
git show v1.0.0
# For annotated: shows tagger, date, message + commit diff
# For lightweight: shows only the commit
# ─── List all tags ───
git tagKey Takeaways
- Tags are fixed pointers to commits — they don't move like branches.
- Annotated tags store metadata (author, date, message) — use these for releases.
- Lightweight tags are just named pointers — use for local bookmarks.
- Every release, deployment, and milestone should have a tag.
Interview Prep
-
Q: What is the difference between a lightweight and an annotated tag? A: A lightweight tag is just a name pointing to a commit — no metadata. An annotated tag is a full Git object storing the tagger's name, email, date, and a message. Annotated tags are recommended for releases because they provide context and can be GPG-signed.
-
Q: How are tags different from branches? A: Branches are movable pointers that advance with each new commit. Tags are fixed pointers that always reference the same commit. Branches are for ongoing work; tags are for marking specific milestones.
-
Q: Why should releases be tagged? A: Tags provide a human-readable, permanent reference to a specific commit. They enable rollbacks to known-good versions, trigger CI/CD pipelines, and make version tracking and communication clear across the team.