Git Tag

Updated · 11 min read
easyGit 2.53gitgit-tagannotated-tagreleasesinterview

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:

Terminal
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 --oneline
Output
16c8a88 (HEAD -> main, origin/main) Add the hostel fee
ec85dfe Add the late fee
4426486 Add the term fee

Two Kinds of Tags

Lightweight tagAnnotated tag
Created withgit tag v1.0.0git tag -a v1.0.0 -m "message"
StoresOnly a name pointing to a commitA tag object: the tagger, the date, a message (and optionally a signature)
LikeA bookmarkA stamp with a label, a date and a signature
Use it forPrivate, temporary marksReleases 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.

Lightweight and annotated tags

Create an Annotated Tag

The school accepts the current version for the first release. Navika tags it:

Terminal
git tag -a v1.0.0 -m "First release for the school office"
git tag
git show v1.0.0
Output
v1.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,000

git 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:

Terminal
git log --oneline
Output
16c8a88 (HEAD -> main, tag: v1.0.0, origin/main) Add the hostel fee
ec85dfe Add the late fee
4426486 Add the term fee

Create a Lightweight Tag

A lightweight tag is just a name. Navika marks the commit she is testing, for herself:

Terminal
git tag testing-hostel
git show --oneline -s testing-hostel
Output
16c8a88 (HEAD -> main, tag: v1.0.0, tag: testing-hostel, origin/main) Add the hostel fee

git 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:

Terminal
git tag -a v0.9.0 -m "Trial version" HEAD~1
git log --oneline
Output
16c8a88 (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 fee

List and Find Tags

Terminal
git tag -l "v*"
git tag -n
Output
v0.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:

Terminal
git push origin v1.0.0
Output
To ../fee-tracker.git
 * [new tag]         v1.0.0 -> v1.0.0
CommandPushes
git push origin <tag>One tag
git push --tagsAll tags, including lightweight and private ones
git push --follow-tagsThe 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:

Terminal
git tag -d testing-hostel
Output
Deleted 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:

Terminal
git switch --detach v0.9.0
Output
HEAD is now at ec85dfe Add the late fee

To fix a bug in an old release, create a branch from its tag:

Terminal
git switch --quiet -c hotfix/1.0.1 v1.0.0
git log --oneline -1
Output
16c8a88 (HEAD -> hotfix/1.0.1, tag: v1.0.0, origin/main, main) Add the hostel fee

Syntax

Terminal
git tag [-a] <name> [<commit>] [-m "<message>"]
git tag [-l "<pattern>"] [-n]
git tag -d <name>
CommandIt is used to
git tag -a v1.0.0 -m "<message>"Create an annotated tag on HEAD
git tag v1.0.0Create 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.0Show a tag and its commit
git push origin v1.0.0Push one tag
git push --follow-tagsPush commits with their annotated tags
git tag -d v1.0.0Delete a local tag
git push origin --delete v1.0.0Delete a tag on the server
git switch -c <branch> v1.0.0Start 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:

Terminal
git cat-file -t v1.0.0
git cat-file -p v1.0.0
Output
tag
object 16c8a88ee16c217c337ce3018c64b8a1bb250d30
type commit
tag v1.0.0
tagger Navika Anamaneni <navika@example.com> 1767629760 -0600
 
First release for the school office

The 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
Terminal
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 origin
Output
d04642b90b3c37536847491c405906cc7c8a941c	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.

Quick check: Git tag

4 questions
1What is the main difference between a tag and a branch?
2Which command creates an annotated tag?
3You ran git push. Is your new tag on the server?
4How do you start fixing release v1.0.0?

Key Takeaways

Quick reference

CommandIt is used to
git tag -a v1.0.0 -m "<message>"Tag a release
git tagList tags
git show v1.0.0Show a tag
git push --follow-tagsPush commits and their annotated tags
git push origin v1.0.0Push one tag
git tag -d v1.0.0Delete a local tag
git push origin --delete v1.0.0Delete a tag on the server
git switch -c hotfix/1.0.1 v1.0.0Branch from a tag

Was this tutorial helpful?

Lesson 52 of 106