Skip to content
Bash

Git Tags

Version tag management.

By EZ4Code Team
gittag

Code

#!/bin/bash

# View tags
git tag
git tag -l "v1.*"        # Filter by pattern
git tag -l --sort=-v:refname  # Sort by version descending

# Create tag
# Lightweight tag
git tag v1.0

# Annotated tag (recommended)
git tag -a v1.0 -m "Release version 1.0"
git tag -a v1.0 <commit-hash> -m "Tag specific commit"

# View tag info
git show v1.0
git cat-file -t v1.0  # View tag type

# Push tags
git push origin v1.0        # Push single tag
git push origin --tags      # Push all tags
git push --follow-tags      # Push with tags

# Delete tag
git tag -d v1.0             # Delete local tag
git push origin --delete v1.0  # Delete remote tag
git push origin :refs/tags/v1.0  # Delete remote tag (old syntax)

# Checkout tag
git checkout v1.0           # Enter detached HEAD state
git checkout -b version-1.0 v1.0  # Create branch

# Semantic versioning
# v1.0.0: major.minor.patch
# 1.0.0 -> 2.0.0: Incompatible API changes
# 1.0.0 -> 1.1.0: Backward-compatible new features
# 1.0.0 -> 1.0.1: Backward-compatible bug fixes

# Automated tagging
# git tag -a "v$(date +%Y%m%d)" -m "Daily build"

Explanation

Git tags mark specific commits; annotated tags store extra info; they must be pushed to remote manually.

More Bash Snippets