What is a tag in Git?
A tag in Git is a named marker on a specific commit, usually used to denote a version or a release.
In simpler terms:
a tag is a "label" on a commit with a readable name like v1.2.0.
Why tags are needed
Tags let you:
- mark releases and versions
- easily go back to a needed state of the code
- trigger CI/CD based on a version
- have a stable point in history (unlike branches)
A branch "moves", a tag does not.
What this looks like in practice
Commit history:
A---B---C---D---E
↑
v1.0.0The v1.0.0 tag points exactly at commit C and will always point at it.
Main types of tags
1. Lightweight tag
- just a reference to a commit
- no description or metadata
bash
git tag v1.0.0Rarely used, mostly for local markers.
2. Annotated tag - recommended
- contains the author
- the date
- a message
- stored as a separate object in Git
bash
git tag -a v1.0.0 -m "Release version 1.0.0"These are the tags used for releases.
Tags and releases (important point)
- A tag is a Git object
- A release is an entity of the platform (GitHub / GitLab)
Usually:
- a
v1.2.0tag is created - based on it, a release with a changelog is created
How tags work with a remote repository
By default, tags are not pushed automatically.
bash
git push origin v1.0.0Or all at once:
bash
git push --tagsTags in CI/CD
Very often:
- a pipeline is triggered by a tag
- deployment to production happens only from tags
- the tag name equals the application's version
Example:
text
v1.3.2 → deploy to productionWhat is important to emphasize in an interview
- a tag is not a branch
- a tag does not move
- a tag points to a specific commit
- annotated tags are used for releases
Short answer for an interview
A tag in Git is a named marker on a specific commit, usually used to denote a version or a release. Unlike a branch, a tag does not change and always points to the same state of the code.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.