Git Tag
A school marks important days on its calendar with labels: "Annual Day", "Exam Week", "Sports Day". The days pass, but the labels stay where they were put, so years later anyone can look up what happened on Annual Day 2026.
A tag is that label for a commit. A branch moves forward with every commit, but a tag stays on the commit you gave it to, forever. Teams tag the commit of every release, such as v1.0.0, so that anyone can find, build or fix exactly the version that customers have, long after main has moved on.
In this lesson, you will create the two kinds of tags, look at them, tag older commits, share tags with your team, and start work from a tag.
The Starting Point
Navika's project has three commits, and a stand-in server as in the previous lessons:
git init --bare --quiet fee-tracker.git
mkdir fee-tracker
cd fee-tracker
git init --quiet
echo 'Term 1 fee: $12,000' > fees.txt
git add fees.txt
git commit --quiet -m "Add the term fee"
echo 'Late fee: $250' >> fees.txt
git commit --quiet -am "Add the late fee"
echo 'Hostel fee: $9,000' >> fees.txt
git commit --quiet -am "Add the hostel fee"
git remote add origin ../fee-tracker.git
git push --quiet -u origin main
git log --oneline16c8a88 (HEAD -> main, origin/main) Add the hostel fee
ec85dfe Add the late fee
4426486 Add the term feeTwo Kinds of Tags
| Lightweight tag | Annotated tag | |
|---|---|---|
| Created with | git tag v1.0.0 | git tag -a v1.0.0 -m "message" |
| Stores | Only a name pointing to a commit | A tag object: the tagger, the date, a message (and optionally a signature) |
| Like | A bookmark | A stamp with a label, a date and a signature |
| Use it for | Private, temporary marks | Releases and anything you share |
Most tools, including git describe and git push --follow-tags, treat annotated tags as the real ones. Use annotated tags for releases.
Create an Annotated Tag
The school accepts the current version for the first release. Navika tags it:
git tag -a v1.0.0 -m "First release for the school office"
git tag
git show v1.0.0v1.0.0
tag v1.0.0
Tagger: Navika Anamaneni <navika@example.com>
Date: Mon Jan 5 10:16:00 2026 -0600
First release for the school office
commit 16c8a88ee16c217c337ce3018c64b8a1bb250d30 (HEAD -> main, tag: v1.0.0, origin/main)
Author: Navika Anamaneni <navika@example.com>
Date: Mon Jan 5 10:11:00 2026 -0600
Add the hostel fee
diff --git a/fees.txt b/fees.txt
index b73e396..e6cd827 100644
--- a/fees.txt
+++ b/fees.txt
@@ -1,2 +1,3 @@
Term 1 fee: $12,000
Late fee: $250
+Hostel fee: $9,000git show displays the tag first, with its tagger, date and message, and then the commit it points to. git log shows tags next to commits too:
git log --oneline16c8a88 (HEAD -> main, tag: v1.0.0, origin/main) Add the hostel fee
ec85dfe Add the late fee
4426486 Add the term feeCreate a Lightweight Tag
A lightweight tag is just a name. Navika marks the commit she is testing, for herself:
git tag testing-hostel
git show --oneline -s testing-hostel16c8a88 (HEAD -> main, tag: v1.0.0, tag: testing-hostel, origin/main) Add the hostel feegit show goes straight to the commit: there is no tagger and no message, because a lightweight tag stores none.
Tag an Older Commit
Tags don't have to be on the newest commit. Name the commit at the end. The office had in fact used the late fee version as a trial, v0.9.0:
git tag -a v0.9.0 -m "Trial version" HEAD~1
git log --oneline16c8a88 (HEAD -> main, tag: v1.0.0, tag: testing-hostel, origin/main) Add the hostel fee
ec85dfe (tag: v0.9.0) Add the late fee
4426486 Add the term feeList and Find Tags
git tag -l "v*"
git tag -nv0.9.0
v1.0.0
testing-hostel Add the hostel fee
v0.9.0 Trial version
v1.0.0 First release for the school office-l with a pattern lists only matching tags, and -n adds the first line of each tag's message (for a lightweight tag, the commit's subject). Tags are listed alphabetically. For version numbers, git tag --sort=-v:refname sorts them as versions, newest first.
Share Tags
git push doesn't send tags. Push them explicitly:
git push origin v1.0.0To ../fee-tracker.git
* [new tag] v1.0.0 -> v1.0.0| Command | Pushes |
|---|---|
git push origin <tag> | One tag |
git push --tags | All tags, including lightweight and private ones |
git push --follow-tags | The commits being pushed, plus every annotated tag on a commit in their history that the server doesn't have yet |
--follow-tags is the safe everyday choice: release tags travel with the history they belong to, and private lightweight tags like testing-hostel stay local. Set git config --global push.followTags true to make it the default.
Teammates get tags with every git fetch or git pull for the commits they fetch, or all of them with git fetch --tags.
Delete a Tag
testing-hostel is no longer needed:
git tag -d testing-hostelDeleted tag 'testing-hostel' (was 16c8a88)A tag that was pushed must also be deleted on the server with git push origin --delete <tag>, and teammates must delete their copies themselves.
Work from a Tag
A tag is not a branch, so switching to it puts you in detached HEAD (see "HEAD and Detached HEAD"). That is fine for looking around or building the old version:
git switch --detach v0.9.0HEAD is now at ec85dfe Add the late feeTo fix a bug in an old release, create a branch from its tag:
git switch --quiet -c hotfix/1.0.1 v1.0.0
git log --oneline -116c8a88 (HEAD -> hotfix/1.0.1, tag: v1.0.0, origin/main, main) Add the hostel feeSyntax
git tag [-a] <name> [<commit>] [-m "<message>"]
git tag [-l "<pattern>"] [-n]
git tag -d <name>| Command | It is used to |
|---|---|
git tag -a v1.0.0 -m "<message>" | Create an annotated tag on HEAD |
git tag v1.0.0 | Create a lightweight tag |
git tag -a v0.9.0 <commit> -m "..." | Tag an older commit |
git tag -l "v1.*" | List matching tags |
git show v1.0.0 | Show a tag and its commit |
git push origin v1.0.0 | Push one tag |
git push --follow-tags | Push commits with their annotated tags |
git tag -d v1.0.0 | Delete a local tag |
git push origin --delete v1.0.0 | Delete a tag on the server |
git switch -c <branch> v1.0.0 | Start a branch from a tag |
Common Mistakes
Expecting git push to push tags. It doesn't. Use --follow-tags or push the tag by name.
Using lightweight tags for releases. They have no author, date or message, and git describe skips them by default. Use -a.
Committing on a checked-out tag. You are in detached HEAD, and the commits belong to no branch. Create a branch from the tag first.
Moving a published tag. Others keep the old one. Make a new version instead.
Tag names that look like branch names. A tag and a branch both called release make commands ambiguous. Use version names like v1.2.0 for tags.
Under the Hood
A lightweight tag is only a ref, a file in .git/refs/tags/ containing a commit ID, exactly like a branch that never moves. An annotated tag is a ref pointing to a tag object, a fourth kind of object next to blobs, trees and commits:
git cat-file -t v1.0.0
git cat-file -p v1.0.0tag
object 16c8a88ee16c217c337ce3018c64b8a1bb250d30
type commit
tag v1.0.0
tagger Navika Anamaneni <navika@example.com> 1767629760 -0600
First release for the school officeThe tag object records which object it tags (object, of type commit), its name, the tagger with a timestamp, and the message. Because it is an object with its own ID, it can also be signed, which is covered with security and signing.
Interview Corner
What is a Git tag?
A named reference to a specific commit that doesn't move, typically used to mark releases such as v1.0.0.
What is the difference between a lightweight and an annotated tag?
A lightweight tag is just a ref to a commit. An annotated tag is a full object with the tagger's name, email, date and a message, and can be signed. Annotated tags are recommended for releases.
How do you push tags to a remote?
git push origin <tag> for one tag, git push --tags for all, or git push --follow-tags to push commits together with the annotated tags that point to them.
How do you delete a tag locally and on the remote?
git tag -d <tag> locally, and git push origin --delete <tag> (or git push origin :refs/tags/<tag>) on the remote.
How do you create a fix for an old release?
Create a branch from its tag, git switch -c hotfix/1.0.1 v1.0.0, commit the fix there, and tag the result v1.0.1.
Practice
Challenge: release the hotfix. On hotfix/1.0.1, fix a typo by adding Fees are per term. to fees.txt, commit it, tag it v1.0.1 with an annotated tag, and push the branch with --follow-tags. Then ask the server for its tags.
What does Git print? Before you open the solution, decide which tags the server has at the end. v0.9.0 was never pushed: is it there now?
Show solution
echo "Fees are per term." >> fees.txt
git commit --quiet -am "Say that fees are per term"
git tag -a v1.0.1 -m "Hotfix: clarify that fees are per term"
git push --quiet --follow-tags -u origin hotfix/1.0.1
git ls-remote --tags origind04642b90b3c37536847491c405906cc7c8a941c refs/tags/v0.9.0
ec85dfe25c3e0dcdd1b3e23c73723c627a9c62d3 refs/tags/v0.9.0^{}
e456443035912e606f5f7e504d12a9223af38471 refs/tags/v1.0.0
16c8a88ee16c217c337ce3018c64b8a1bb250d30 refs/tags/v1.0.0^{}
928a9184b9c880ba835c10317313bec0abcd3a69 refs/tags/v1.0.1
1f77d6d9c85fcd8c3147dd4fa595cefa646ee868 refs/tags/v1.0.1^{}All three are there. v1.0.0 was pushed earlier, and --follow-tags sent v1.0.1 with the new commit. It also sent v0.9.0: that annotated tag points to "Add the late fee", which is part of the pushed branch's history, and the server didn't have the tag yet. Only lightweight tags are never sent this way. The lines ending in ^{} show the commit each annotated tag points to.
Checkpoint. In a practice repository, create an annotated tag on the latest commit and another on an older commit, push both, delete one locally and on the server, and create a branch from the other.
Key Takeaways
Quick reference
| Command | It is used to |
|---|---|
git tag -a v1.0.0 -m "<message>" | Tag a release |
git tag | List tags |
git show v1.0.0 | Show a tag |
git push --follow-tags | Push commits and their annotated tags |
git push origin v1.0.0 | Push one tag |
git tag -d v1.0.0 | Delete a local tag |
git push origin --delete v1.0.0 | Delete a tag on the server |
git switch -c hotfix/1.0.1 v1.0.0 | Branch from a tag |
Was this tutorial helpful?