Tags and Releases
Tags in Git are used to mark specific points in history as important β most commonly to mark release versions (e.g., v1.0.0, v2.1.3).
Unlike branches, tags do not move. Once created, they always point to the same commit.
Tags are commonly used for:
- Version releases
- Deployment checkpoints
- Public milestones
- Stable versions for production
Lightweight vs Annotated Tagsβ
Git provides two types of tags:
πΉ Lightweight Tags
A lightweight tag is simply a pointer to a specific commit. Itβs like a bookmark.
Create a lightweight tag:
git tag v1.0.0
This creates a tag pointing to the current HEAD.
You can also tag a specific commit:
git tag v1.0.0 <commit-hash>
Characteristics:
- No extra metadata
- No tag message
- No author/date information
- Simple reference only
Use lightweight tags for:
- Temporary tags
- Internal checkpoints
- Quick local marking
πΉ Annotated Tags (Recommended for Releases)
Annotated tags are full Git objects stored in the repository database.
They contain:
- Tag name
- Tag message
- Tagger name
- Date
- Optional GPG signature
Create an annotated tag:
git tag -a v1.0.0 -m "Release version 1.0.0"
Tag a specific commit:
git tag -a v1.0.0 <commit-hash> -m "Release version 1.0.0"
Why annotated tags are better for releases:
- More professional
- Include release notes message
- Traceable metadata
- Suitable for public repositories
π Best practice: Use annotated tags for production releases.
Listing and Managing Tagsβ
List all tags
git tag
List tags with additional information
git tag -n
Show detailed information about a tag
git show v1.0.0
Pushing Tags to Remoteβ
By default, git push does not push tags.
Push a specific tag
git push origin v1.0.0
Push all tags
git push origin --tags
Push annotated tags only
git push origin --follow-tags
π --follow-tags pushes only annotated tags that are referenced by pushed commits.
Deleting Tagsβ
Delete local tag
git tag -d v1.0.0
Delete remote tag
git push origin --delete v1.0.0
Creating Relase from Tagsβ
In most platforms (GitHub, GitLab, Bitbucket), tags are used to create official releases.
Typical workflow:
- Finish feature development
- Merge into main branch
- Create annotated tag
- Push tag to remote
- Create release notes
Creating Release Notes from Tagsβ
Release notes describe:
- New features
- Bug fixes
- Breaking changes
- Improvements
You can generate release notes manually or automatically.β
Option 1: Manually from Git Log Compare commits between two tags:
git log v1.0.0..v1.1.0 --oneline
This shows all commits included in v1.1.0 but not in v1.0.0.
You can also format it:
git log v1.0.0..v1.1.0 --pretty=format:"- %s"
Example output:
- Add authentication feature
- Fix login validation bug
- Improve API performance
You can copy this into your release notes. Option 2: Using Conventional Commits (Recommended) If your commit messages follow a structured format like:
feat: add payment integration
fix: correct validation logic
docs: update README
You can filter commits:
git log v1.0.0..v1.1.0 --grep="feat\|fix" --pretty=format:"- %s"
This makes release notes cleaner and more professional.
Suggested Versioning Strategy (Semantic Versioning)β
Common version format:
MAJOR.MINOR.PATCH
Example:
1.0.0β Initial release1.1.0β New feature added1.1.1β Bug fix2.0.0β Breaking changes
Rules:
- MAJOR β Breaking change
- MINOR β Backward-compatible feature
- PATCH β Backward-compatible fix
Best Practiceβ
- β Use annotated tags for production releases
- β Follow Semantic Versioning
- β Keep commit messages clean
- β Generate release notes from tag comparison
- β Push tags immediately after creation
- β Never rewrite public release tags
Summaryβ
- Tags mark specific commits as important
- Lightweight tags are simple pointers
- Annotated tags store metadata and are recommended for releases
- Tags are not pushed automatically
- Release notes can be generated using git log
- Use Semantic Versioning for clear version control