DevOps · Infrastructure as Code (IaC) · Git Series – Part 7
GIT taggingTags are essential for marking release versions, milestones, and important points in your Git history. DevOps teams rely heavily on tags for CI/CD pipelines, versioning artifacts, deployment releases, and rollback management.
In this chapter, you’ll learn:
Table of Contents
1. What Is a Git Tag?
A tag is a label that points to a specific commit — usually used for marking a release version.
Examples:
v1.0.0v2.1.3-betarelease-2025-01-01
Tags do not move like branches. They are fixed.
2. Types of Git Tags
Git supports two types:
1. Lightweight Tag
A simple label pointing to a commit.
- No metadata
- No message
- No tagger info
- Very small, fast
Example use: quick local checkpoints.
2. Annotated Tag (Recommended)
A full tag object that contains:
- Tag message
- Tag author
- Tag date
- GPG signing (optional)
Ideal for:
- Production releases
- Versioning IaC
- CI/CD pipelines
- Software release workflows
3. Creating Tags
Create Lightweight Tag
git tag v1.0.0
Create Annotated Tag (Recommended)
git tag -a v1.0.0 -m "Release version 1.0.0"
Tag a specific commit
git tag -a v1.0.0 <commit_hash>
Example:
git tag -a v1.0.0 9fceb02 -m "Production release"
4. Listing Tags
git tag
Sort alphabetically:
git tag --sort=refname
Search for pattern:
git tag -l "v1.*"
5. Viewing Tag Details
For annotated tags:
git show v1.0.0
Shows message + metadata + diff.
6. Pushing Tags to Remote
By default, tags are not pushed when you push commits.
Push a single tag:
git push origin v1.0.0
Push all tags:
git push --tags
CI/CD pipelines often depend on tags, so pushing them is crucial.
7. Deleting Tags
Delete Local Tag
git tag -d v1.0.0
Delete Remote Tag
git push origin --delete v1.0.0
or
git push origin :refs/tags/v1.0.0
8. Renaming a Tag
Git has no rename command; you must recreate it.
git tag new-tag old-tag
git tag -d old-tag
git push origin :refs/tags/old-tag
git push origin new-tag
9. Semantic Versioning (SemVer)
Widely used in DevOps releases.
Format:
MAJOR.MINOR.PATCH
Examples:
1.0.0→ initial stable release1.1.0→ backward-compatible feature added1.1.1→ patch or bug fix2.0.0→ breaking changes
Pre-release labels:
1.0.0-alpha1.0.0-beta1.0.0-rc1
10. How DevOps Pipelines Use Tags
Tags trigger automated workflows in tools such as:
- GitHub Actions
- GitLab CI
- Jenkins
- Azure DevOps
- Ansible Automation Platform
- Argo CD
Common uses:
✔ Triggering production deployments
✔ Packaging releases (Docker, artifacts, ZIPs)
✔ Publishing IaC versions (Terraform, Ansible roles)
✔ Rolling back using previous tags
Example GitHub Actions trigger:
on:
push:
tags:
- 'v*'
11. Hands-On Demo
git init
echo "app v1" > app.txt
git add .
git commit -m "Initial commit"
git tag -a v1.0.0 -m "First stable release"
git show v1.0.0
git push origin v1.0.0
12. Git Tagging Best Practices
✔ Use annotated tags for releases
Lightweight tags are fine for local notes.
✔ Follow semantic versioning
Helps automation and clarity.
✔ Always push tags after release commits
CI/CD pipelines may require them.
✔ Don’t retag different commits
Rewriting tags breaks pipelines.
✔ Maintain consistent naming patterns
Examples:
v1.2.0release-2025-01prod-2025.02.12
13. Summary Table – Tag Commands
| Action | Command |
|---|---|
| Create lightweight | git tag v1.0.0 |
| Create annotated | git tag -a v1.0.0 -m "msg" |
| Tag a commit | git tag v1.0.0 <hash> |
| List tags | git tag |
| View details | git show v1.0.0 |
| Push a tag | git push origin v1.0.0 |
| Push all tags | git push --tags |
| Delete local tag | git tag -d v1.0.0 |
| Delete remote tag | git push origin --delete v1.0.0 |
14. What’s Next?
You now know how to:
✔ Create lightweight & annotated tags
✔ Version releases with semantic versioning
✔ Push & delete tags
✔ Use tags in DevOps pipelines
✔ Follow best release practices
Next chapter: