What is a Git tag and how does it differ from a branch?
Learn what a Git tag is, the difference between lightweight and annotated tags, how tags differ from branches, and how to push tags to a remote.
Expected Interview Answer
A Git tag is a fixed, named pointer to a specific commit, most often used to mark release points like v1.0.0, and unlike a branch it never moves forward as new commits are made.
There are two kinds: lightweight tags, which are just a simple pointer to a commit, and annotated tags, which are full objects storing a tagger name, date, message, and optional GPG signature, making them the recommended choice for real releases. Because a tag never advances automatically, checking one out puts you in a detached HEAD state, since there is no branch to update. Tags must also be pushed explicitly with git push --tags or git push origin <tagname>, since a normal git push does not include them.
- Marks stable, permanent release points in history
- Annotated tags carry metadata and can be GPG-signed
- Never moves, unlike a branch pointer
- Enables reliable version references like v2.1.0
- Works with CI/CD pipelines to trigger release builds
AI Mentor Explanation
A Git tag is like the official plaque marking the exact ball a bowler took a hat-trick, fixed permanently at that one moment in the match. A branch is more like the live over count, which keeps advancing as play continues. The plaque never moves to a later ball no matter how the match progresses, which is exactly why tags are used to mark a specific, unchanging milestone rather than ongoing play.
Step-by-Step Explanation
Step 1
Choose lightweight or annotated
A lightweight tag is a bare pointer; an annotated tag stores a message, tagger, date, and optional signature.
Step 2
Create the tag
git tag v1.0.0 makes a lightweight tag; git tag -a v1.0.0 -m "message" makes an annotated one on the current commit.
Step 3
Tag a past commit if needed
git tag -a v1.0.0 <hash> -m "..." tags an older commit instead of HEAD.
Step 4
Push the tag explicitly
A plain git push does not send tags; use git push origin v1.0.0 or git push --tags to publish them.
Step 5
Checkout puts you in detached HEAD
Since a tag never moves, checking one out points HEAD directly at that commit rather than any branch.
What Interviewer Expects
- Distinguishes lightweight vs annotated tags
- Explains a tag never moves, unlike a branch
- Knows tags must be pushed explicitly (not included in plain git push)
- Mentions checking out a tag puts you in detached HEAD
- Knows annotated tags can be GPG-signed for verified releases
Common Mistakes
- Assuming git push automatically pushes tags
- Using lightweight tags for real releases instead of annotated ones
- Thinking a tag can move forward like a branch
- Not realizing checking out a tag detaches HEAD
Best Answer (HR Friendly)
“A Git tag is a permanent label marking one exact point in a project's history, usually a release like version 1.0, and unlike a branch it never moves as new work is added. It's the standard way to mark 'this is exactly what we shipped' so anyone can return to that precise version later.”
Code Example
# Lightweight tag
git tag v1.0.0
# Annotated tag (recommended for releases)
git tag -a v1.0.0 -m "First stable release"
# Tags are not pushed by default
git push origin v1.0.0
git push --tagsFollow-up Questions
- What is the difference between a lightweight and an annotated tag?
- Why does checking out a tag put you in a detached HEAD state?
- How do you delete a tag locally and on the remote?
- How can tags be used to trigger a CI/CD release pipeline?
- What does GPG-signing a tag accomplish?
MCQ Practice
1. What does a Git tag point to?
Unlike a branch, a tag is a fixed pointer to one commit and never advances automatically as new commits are made.
2. Which type of tag stores a message, tagger name, and date?
Annotated tags are full Git objects storing metadata like the tagger, date, and message, and can also be GPG-signed.
3. Does a plain git push send tags to the remote?
Tags are not included in a normal git push; you must use git push --tags or push the specific tag name.
Flash Cards
What is a Git tag? — A fixed, named pointer to one specific commit that never moves, typically used to mark releases.
Lightweight vs annotated tag? — Lightweight is a bare pointer; annotated stores a message, tagger, date, and can be GPG-signed.
Does git push send tags automatically? — No — tags must be pushed explicitly with git push --tags or git push origin <tagname>.
What happens when you checkout a tag? — You enter a detached HEAD state, since a tag has no branch to update.