Git Tag
A tag is a permanent name for a commit. It is mostly used to mark release versions like v1.0 or v2.3.1. Unlike a branch, a tag does not move when you make new commits.
Syntax
git tag
git tag <name>
git tag -a <name> -m "message"
git tag -d <name>
git push origin <name>
git push origin --tags
Types of tags
- Lightweight tag: only a name for a commit. Quick and simple.
- Annotated tag: stores a message, the name of the tagger and the date. This is recommended for releases.
Create tags
$ git tag v0.1
$ git tag -a v1.0 -m "Version 1.0"
$ git tag
v0.1
v1.0
Tag an older commit
You can add a tag to any earlier commit by giving its hash (or a name like HEAD~1).
$ git tag v0.9 HEAD~1
$ git log –oneline
277a982 (HEAD -> main, tag: v1.0, tag: v0.1) Fix a bug
a96a5d8 (tag: v0.9) First release
See the details of a tag
$ git show v1.0 –no-patch
tag v1.0
Tagger: Robin Sharma <robin@example.com>
Date: Sat Jan 10 11:10:00 2026 +0000
Version 1.0
commit 277a9828fa0629278b30adf887b38241bffff3c2 (HEAD -> main, tag: v1.0, tag: v0.1)
Author: Robin Sharma <robin@example.com>
Date: Sat Jan 10 10:56:00 2026 +0000
Fix a bug
The annotated tag shows who made it, when, and the message. A lightweight tag shows only the commit.
Search tags
$ git tag -l "v0.*"
v0.1
v0.9
Delete a tag
$ git tag -d v0.1
Deleted tag 'v0.1' (was 277a982)
$ git tag
v0.9
v1.0
Share tags
The command git push does not send tags. You must push them yourself:
git push origin v1.0
git push origin --tags
git push origin --delete v1.0
Go back to a tag
git switch --detach v1.0
git switch -c hotfix-1.0.1 v1.0
Version numbers
Many projects use semantic versioning: MAJOR.MINOR.PATCH, for example 2.4.1. Increase MAJOR for big breaking changes, MINOR for new features that work with the old code, and PATCH for bug fixes.
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |