Git Notes
Learn how to create, list, and manage Git tags for releases and milestones. Understand lightweight vs annotated tags, semantic versioning, and tag workflows.
Git tags mark specific commits as important milestones — typically used for release versions (v1.0.0, v2.1.3). Unlike branches, tags do not move; they permanently point to a specific commit.
Types of Tags
Lightweight Tags
Simple pointers to a commit (like a branch that does not move):
git tag v1.0.0Annotated Tags (Recommended)
Full objects with tagger name, date, message, and optional GPG signature:
git tag -a v1.0.0 -m "Release version 1.0.0"# No output on success
# View annotated tag details
git show v1.0.0tag v1.0.0
Tagger: Jane Doe <jane@example.com>
Date: Mon Jan 15 10:00:00 2024 -0500
Release version 1.0.0
commit a1b2c3d4e5f6789012345678901234567890abcd
Author: Jane Doe <jane@example.com>
Date: Mon Jan 15 09:45:00 2024 -0500
Final preparations for v1.0.0 releaseCreating Tags
Tag Current Commit
# Annotated (recommended)
git tag -a v2.0.0 -m "Major release with new UI"
# Lightweight
git tag v2.0.0-betaTag a Past Commit
git tag -a v1.5.0 -m "Patch release" abc1234Tag with Semantic Versioning
| MAJOR: Breaking changes (v1.0.0 | v2.0.0) |
| MINOR: New features, backwards compatible (v1.0.0 | v1.1.0) |
| PATCH: Bug fixes, backwards compatible (v1.0.0 | v1.0.1) |
| Pre-release | v2.0.0-beta.1, v2.0.0-rc.1 |
| Build metadata | v1.0.0+build.123 |
Listing Tags
# List all tags
git tagv1.0.0 v1.1.0 v1.2.0 v2.0.0 v2.0.1
# Filter tags by pattern
git tag -l "v2.*"v2.0.0 v2.0.1
# Sort by version number
git tag --sort=version:refname# Show tags with messages
git tag -nv1.0.0 Initial stable release v1.1.0 Add user authentication v2.0.0 Major release with new UI
Pushing Tags
Tags are NOT pushed by default with git push:
# Push a specific tag
git push origin v1.0.0
# Push ALL tags
git push origin --tags
# Push only annotated tags (not lightweight)
git push origin --follow-tagsEnumerating objects: 1, done. Counting objects: 100% (1/1), done. Writing objects: 100% (1/1), 175 bytes | 175.00 KiB/s, done. Total 1 (delta 0), reused 0 (delta 0) To https://github.com/user/repo.git * [new tag] v1.0.0 -> v1.0.0
Deleting Tags
# Delete local tag
git tag -d v1.0.0-betaDeleted tag 'v1.0.0-beta' (was a1b2c3d)
# Delete remote tag
git push origin --delete v1.0.0-beta
# or
git push origin :refs/tags/v1.0.0-betaChecking Out Tags
# View code at a tag (detached HEAD)
git checkout v1.0.0Note: switching to 'v1.0.0'. You are in 'detached HEAD' state... HEAD is now at a1b2c3d Final preparations for v1.0.0 release
# Create a branch from a tag (to make changes)
git checkout -b hotfix/v1.0.1 v1.0.0Release Workflow with Tags
# 1. Finish all work for the release
git checkout main
git pull origin main
# 2. Create annotated tag
git tag -a v1.2.0 -m "Release v1.2.0: Add payment integration"
# 3. Push the tag
git push origin v1.2.0
# 4. GitHub automatically creates a release (if configured)
# Or create manually on GitHub Releases pageComparing Tags
# See commits between two tags
git log v1.0.0..v2.0.0 --onelinea1b2c3d Add new dashboard b2c3d4e Refactor authentication c3d4e5f Fix database connection d4e5f6g Update dependencies
# See file changes between tags
git diff v1.0.0 v2.0.0 --statInterview Questions
- What is the difference between a lightweight and annotated tag?
A lightweight tag is just a pointer to a commit (like a branch that does not move). An annotated tag is a full Git object with tagger info, date, message, and optional GPG signature. Annotated tags are recommended for releases.
- Why are tags not pushed by default?
Tags are considered local metadata by Git. This prevents accidentally publishing tags. You must explicitly push with git push origin <tag> or git push --tags.
- How do you create a tag for a past commit?
Use git tag -a v1.0.0 -m "message" <commit-hash>. This creates an annotated tag pointing to the specified historical commit.
- What happens when you checkout a tag?
You enter a detached HEAD state because tags point to commits, not branches. If you need to make changes, create a branch from the tag with git checkout -b branch-name tag-name.
- How is semantic versioning used with Git tags?
Tags follow the format vMAJOR.MINOR.PATCH. MAJOR for breaking changes, MINOR for backward-compatible features, PATCH for backward-compatible fixes. Pre-release versions use suffixes like -beta.1 or -rc.1.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Git Tag - Mark Important Points in History.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Git & GitHub topic.
Search Terms
git-github, git & github, git, github, advanced, tag, git tag - mark important points in history
Related Git & GitHub Topics