Git & GitHub
/Intermediate
git tag
Definition
Tags are ref marks pointing to specific points in Git history. They are generally used to capture a point in history that is used for a marked version release (i.e. v1.0.0).
Explain Like I'm New
A permanent, unmoving bookmark. While branch pointers (`main`, `dev`) constantly move forward as new commits are added, a Tag is glued to a single commit forever. It says 'This exact moment in time is Version 1.0'.
Real World Example
When a software company releases an update, they tag the commit `v2.4.1`. If a user finds a bug in v2.4.1, developers can instantly jump back to that exact tag to investigate.
Common Use Cases
- •Software versioning (Semantic Versioning)
- •Creating release milestones
Terminal Output
bash / terminal
# Create a lightweight tag on the current commit
$ git tag v1.0.0
# Create an Annotated tag (Recommended for releases!)
$ git tag -a v2.0.0 -m "Major release including the new UI overhaul"
# View all tags
$ git tag
# View the specific details of a tag
$ git show v2.0.0
# Push all your local tags to GitHub (Crucial step!)
$ git push origin --tags
Interview Questions
basic
- What is the difference between an 'Annotated' tag and a 'Lightweight' tag?
intermediate
- Does `git push` automatically upload your tags to GitHub?