How does a tag differ from a branch?
A tag and a branch in Git differ in their role and behavior in the commit history.
In short: a branch is a "live pointer," while a tag is a "fixed marker."
The main difference
- A branch points to the last commit and moves forward with every new commit
- A tag points to a specific commit and never changes
A simple example
History:
A---B---C---D
- the
mainbranch →D - the
v1.0.0tag →B
If a new commit is added:
A---B---C---D---E
main→Ev1.0.0→ stillB
Differences by purpose
Branch
- used for development
- combined via merge/rebase
- can change and be rewritten
- often lives temporarily
Tag
- used for versions and releases
- does not participate in merges
- does not change
- fixes the state of the code
Differences in behavior
| Criterion | Branch | Tag |
|---|---|---|
| Moves with new commits | yes | no |
| Can be committed to | yes | no |
| Used for development | yes | no |
| Marks a version | no | yes |
| Can be deleted | yes | yes (but rarely) |
Frequently asked in interviews
Can you commit to a tag? No. Commits are made to a branch; a tag only points to a commit.
Can a tag be "moved"? Technically, yes (delete and recreate it), but this is bad practice for releases.
Short answer for an interview
A branch is a moving pointer to the last commit and a development tool, while a tag is an immutable marker on a specific commit, used to fix a version or a release.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.