Git tag = Permanent label on a specific commit.
Main use: Mark versions (v1.0, v2.0, etc.)
Difference from branches:
Analogy: Tag = a "Version 1.0" sticker on a notebook page.
git tag v1.0 # Simple taggit tag -a v1.0 -m "Version 1.0 - First stable release"mkdir demo-tags && cd demo-tags
git init
echo "print('app v0.1')" > app.py
git add . && git commit -m "Initial version"
echo "print('app v0.2')" > app.py
git add . && git commit -m "Bug fixes"
echo "print('app v1.0')" > app.py
git add . && git commit -m "First stable version"# Simple tag
git tag v1.0
# Tag with a message
git tag -a v1.0-stable -m "Version 1.0 - Production ready"
# Tag on a previous commit
git log --oneline # See the hashes
git tag v0.2-beta <hash> # Tag on a specific commitgit tag # All tags
git tag -l "v1.*" # Tags matching a pattern
git show v1.0 # Tag detailsgit checkout v1.0 # Go to the tagged commit
git checkout main # Go back to maingit push origin v1.0 # Push a specific tag
git push origin --tags # Push all tagsvMAJOR.MINOR.PATCH
- v1.0.0 → First stable release
- v1.0.1 → Bug fix
- v1.1.0 → New feature (backward compatible)
- v2.0.0 → Breaking changes# Development finished
git checkout main
git pull origin main
# Release tag
git tag -a v1.2.0 -m "Release v1.2.0 - Add user authentication"
# Push code + tags
git push origin main
git push origin v1.2.0
# Or push everything at once:
git push origin main --tags# Delete a local tag
git tag -d v1.0
# Delete a remote tag
git push origin --delete v1.0
# Modify a tag (recreate)
git tag -d v1.0 # Delete locally
git push origin --delete v1.0 # Delete remotely
git tag -a v1.0 -m "Corrected message" # Recreate
git push origin v1.0 # Re-push1. Production release:
git tag -a v2.1.0 -m "Production release v2.1.0"
git push origin v2.1.0
# Deploy version v2.1.0 to production2. Go back to a previous version:
git checkout v2.0.0 # Go back to a stable version
git checkout -b hotfix-v2.0.0 # Create a hotfix branch3. Compare versions:
git diff v1.0.0 v2.0.0 # See all the changesTags = Permanent milestones of your project. Use them for all your releases!