The Hook (The "Byte-Sized" Intro)
A well-tagged repo tells its entire release history at a glance. A poorly-tagged repo has entries like test, final, really-final, and v1-fixed-again. Follow these 6 rules and your tags will be trustworthy, consistent, and useful for every part of the pipeline.
📖 What is Tagging Best Practices?
Guidelines for creating tags that are consistent, informative, and reliable across the team.
Conceptual Clarity
The 6 rules:
| # | Rule | Why |
|---|---|---|
| 1 | Use annotated tags for releases | Stores who, when, and why |
| 2 | Follow SemVer naming | v1.2.3 format is universally understood |
| 3 | Tag only stable points | Tags should represent tested, deployable commits |
| 4 | Always push tags explicitly | Tags don't auto-push |
| 5 | Never move release tags | Teams depend on tag immutability |
| 6 | Use pre-release labels | v2.0.0-beta.1 clearly signals instability |
Real-Life Analogy
Tags are like product version stamps on the packaging. If you stamp "v1.0" on an untested build, customers lose trust. If you keep changing what "v1.0" points to, nobody knows what they're running.
Visual Architecture
Why It Matters
- Trust: Consistent tagging builds confidence in the release process.
- Automation: CI/CD relies on predictable tag patterns to trigger deployments.
- Debugging: Well-tagged repos make rollbacks instant and reliable.
- Communication: Version numbers communicate intent across teams.
Code
# ─── Good tagging workflow ───
# 1. Ensure all tests pass
# 2. Create annotated tag with SemVer
git tag -a v1.2.0 -m "Release: Add dark mode, fix #167"
# 3. Push the tag
git push origin v1.2.0
# ─── Configure auto-push for annotated tags ───
git config --global push.followTags true
# ─── Pre-release tagging ───
git tag -a v2.0.0-rc.1 -m "Release candidate 1"
git push origin v2.0.0-rc.1
# ─── Naming convention ───
# ✅ v1.0.0, v1.0.1, v2.0.0-beta.1
# ❌ release-1, final, test-tag, v1-fixedKey Takeaways
- Always use annotated tags with meaningful messages for releases.
- Follow SemVer (
v1.2.3) for consistent, understandable versioning. - Only tag tested, stable commits — never tag WIP or untested code.
- Never move release tags after pushing — teams depend on their immutability.
Interview Prep
-
Q: Why should release tags be immutable? A: Teams, CI/CD pipelines, and deployment systems depend on tags pointing to specific commits. Moving a tag can cause confusion, re-trigger builds, break rollbacks, and erode trust in the release process.
-
Q: What naming convention should tags follow? A: Semantic Versioning prefixed with
v:v1.0.0for stable,v2.0.0-beta.1for pre-release. This is universally understood and compatible with version sorting tools and CI/CD trigger patterns. -
Q: Why should you only tag stable commits? A: Tags represent deployable milestones. Tagging untested code creates false confidence, can trigger production deployments of broken code, and makes rollback strategies unreliable.