A user reports a bug in version 1.0. Since that version was released, main has moved forward by dozens of commits. Which commit was the one released? If nobody marked it, all you can do is guess from dates and commit messages.
A tag solves this. A tag is a permanent name stuck on one commit, usually to mark a release version (a version given to users) such as v1.0. Think of a book. The author keeps revising the manuscript, but the "first printing" copies people already bought stay the same. In Git, each version of the manuscript is one commit. A branch is like the manuscript that keeps changing: the branch always moves to the newest version. A tag is like the "first printing" stamp: it points at one version of the manuscript, one commit, forever.
Make a tag and list them
These two commands make a tag, then list the tags:
git tag v1.0 # stick the tag v1.0 on the commit you're on
git tag # list every tag
Here is Git's answer to a first commit and those two commands, in a repo whose file app.js holds console.log("v1") (your hashes will differ):
$ git commit -m "first release"
[main (root-commit) 4c1d2e3] first release
1 file changed, 1 insertion(+)
$ git tag v1.0
$ git tag
v1.0
git tag v1.0prints nothing when it works. The tag sticks to the commit where HEAD (the marker of where you are now) is.git tagwith no name lists every tag, alphabetically.git tag -landgit tag --listdo the same.- A tag needs a commit. In a repo with no commits, there's no commit to stick the tag on.
Tags stay, branches move
Continue the repo from that example with two more commits. In this table, C1 is the commit "first release", and C2 and C3 are the two new commits:
| Step | Command | main at |
v1.0 at |
|---|---|---|---|
| 1 | git commit -m "first release" |
C1 | not yet |
| 2 | git tag v1.0 |
C1 | C1 |
| 3 | git commit -m "add feature 2" |
C2 | C1 |
| 4 | git commit -m "add feature 3" |
C3 | C1 |
The branch you're on moves to each new commit, but a tag never moves. v1.0 stays on C1, unless you delete it and make it again yourself. git log --oneline shows where both are:
$ git log --oneline
9e8f7a6 (HEAD -> main) add feature 3
5b4c3d2 add feature 2
4c1d2e3 (tag: v1.0) first release
Because it doesn't move, a tag is right for marking the exact code released as v1.0. If a bug report about v1.0 arrives next week, you know which commit to look at.
Lightweight and annotated
There are two kinds of tag:
- Lightweight:
git tag v1.0. Just a name pointing at a commit, with no other data. - Annotated:
git tag -a v1.1 -m "Release 1.1: features 2 and 3". The option-amakes a tag that stores metadata (data about the tag itself): the name and email of whoever made it (the tagger), the date, and a message. Without-m, Git opens a text editor for you to write the message.
In the exercise, v1.0 must be an annotated tag: git tag v1.0 alone is not enough.
git show shows the difference. For an annotated tag, git show shows the tag's own data first, then the commit:
$ git show v1.1
tag v1.1
Tagger: Sari <[email protected]>
Date: Thu Oct 8 10:15:00 2026 +0700
Release 1.1: features 2 and 3
commit 9e8f7a6b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5e6f (HEAD -> main, tag: v1.1)
Author: Sari <[email protected]>
Date: Thu Oct 8 10:12:00 2026 +0700
add feature 3
After that, Git also prints the changes in that commit. git show v1.0, the lightweight one, starts directly at the commit ... line, because there's no tag data to show. For releases, use annotated: it records who released, when, and the notes.
Sending tags to GitHub
git push is the command that sends the commits on your branch to an online repo (a copy of your repository on the internet, usually on GitHub). Tags are made on your computer only, and a plain git push doesn't send them. Send tags separately:
git push origin v1.0 # send one tag
git push origin --tags # send every tag
origin is the name usually given to that online repo. How to connect to an online repo is covered in the Git Remote & Clone lesson, and how to push in the Git Push & Pull lesson. For now, just remember: tags are sent separately.
💡 Tag names: semantic versioning
Most projects name tags with the pattern vMAJOR.MINOR.PATCH, such as v1.4.2. A small bug fix raises PATCH (v1.4.3). A new feature that breaks nothing raises MINOR (v1.5.0). A change that breaks code written for the old version raises MAJOR (v2.0.0). The v1.0 in this exercise is the short form of that pattern.
⚠️ Why was the tag refused, or why didn't it reach GitHub?
- Tagging before the first commit. There's no commit to stick it on, so Git refuses. This exercise also checks that
mainhas at least 1 commit. - The same name twice. A second
git tag v1.0is refused withfatal: tag 'v1.0' already exists. Use a new name such asv1.1. If the old tag really is on the wrong commit, delete it first withgit tag -d v1.0. That only deletes the tag on your computer: if the tag was already pushed, also delete it on GitHub withgit push origin --delete v1.0. - Thinking tags get pushed. A plain
git pushonly sends branches. Tags needgit push origin v1.0orgit push origin --tags. - A typo in the name.
V1.0,v1.0.andv 1.0are notv1.0. This exercise checks for exactlyv1.0.
TL;DR: A tag is a permanent name on one commit, for marking a release version such as v1.0. git tag v1.0 makes a lightweight tag, which only points at the commit. git tag -a v1.0 -m "message" makes an annotated tag, which also stores metadata: who made it (the tagger), the date and a message. git tag lists the tags, and git show v1.0 shows what's in that tag. The branch you're on moves to each new commit, but a tag stays in place. A plain git push, which sends your commits to an online repo such as GitHub, doesn't send tags. Send them with git push origin v1.0 (one tag) or git push origin --tags (every tag). origin is the name of that online repo.
⚡ Stick a name on one commit
Write:
git tag v1.0
git tag
Meaning: A tag is a permanent name stuck on one commit, usually to mark a release version such as v1.0. git tag v1.0 sticks a tag on the commit you're on, and git tag with no name lists the tags. A tag needs a commit, so make a commit first.
This exercise checks for the exact name v1.0.
⚡ Tags stay, branches move
Guess first: you stick v1.0 on a commit, then make two more commits. Where is v1.0 now?
Still on the same commit. The branch you're on moves to each new commit, but a tag never moves.
Meaning: Because it doesn't move, a tag is right for marking the exact code released as v1.0.
⚡ Lightweight and annotated
Write:
git tag -a v1.1 -m "Release 1.1: features 2 and 3"
Meaning: A lightweight tag (git tag v1.0) is just a name pointing at a commit. An annotated tag (the option -a) also stores metadata (data about the tag itself): who made it (the tagger), the date and the message written after -m. For releases, use annotated. In the exercise, v1.0 must be an annotated tag.
⚡ Send tags separately
Write:
git push origin v1.0
Meaning: git push sends the commits on your branch to an online repo, for example on GitHub. origin is the name usually given to that online repo. A plain git push sends only branches. Tags go separately: one at a time like the command above, or all at once with git push origin --tags.