Tags
Last updated
Lola Remy's 80th birthday is coming, and Ana wants to print the recipe book as it is on that day. A tag is a name for one commit that never moves, like "v1.0" or "birthday-print". In this lesson you'll make both kinds of tag and see how they differ from branches.
By the end of this lesson you can
- Make lightweight and annotated tags, and say how they differ
- Explain that a tag stays on its commit while branches move on
- Read version numbers like v1.2.0
A tag is a label that stays
A tag, like a branch, is a name pointing at a commit. The difference: a branch moves when you commit on it, and a tag never moves. A tag marks one moment for good: a release, a printed copy, the version you handed in.
$ git tag birthday-print $ git log --oneline -2 67e435d (HEAD -> main, tag: birthday-print) Cover the leche flan with foil ba04ca2 Add lumpiang shanghai recipe
67e435dHEAD →main⚑ birthday-print Cover the leche flan with foilba04ca2Add lumpiang shanghai recipe98a5edcAdd a script that builds the index paged078487Make the sinigang steps clearer145dc1eAdd pancit bihon recipe52d1f4dSay how much salt goes in the adobo1c17fadAdd a README9c53888Add leche flan recipe1f359a2Add sinigang recipe601c654Add adobo recipe
birthday-print.Lightweight and annotated
Git has two kinds:
- Lightweight:
git tag birthday-print. Just a name for a commit, like a branch that doesn't move. - Annotated:
git tag -a v1.0 -m "First printed edition". Git stores a small object with the tag's name, who made it, when, and a message.git show v1.0shows all of that above the commit.
Git's own documentation says annotated tags are meant for releases, and lightweight ones for private or temporary labels. Some commands, like git describe, only look at annotated tags by default.
git tag lists tags. git tag -d name deletes one. A tag can go on any commit: git tag -a v0.9 -m "..." HEAD~3.
Sharing tags. git push doesn't send tags. git push origin v1.0 sends one; Stage 4 covers pushing.
Tag the recipe book
- Make a lightweight tag
birthday-printon the newest commit - Make an annotated tag
v1.0with the message “First printed edition” - Make an annotated tag
v0.1on the first commit, “Lola’s first three recipes” - Show
v1.0and compare it withgit show birthday-print - Make a new commit, then check with
git log --onelinethat the tags stayed behind
Working folder
no changes
Staging area
nothing staged
Repository
10 commits on main
You are in ~/kusina, which has ten commits from two weeks of work.
Commit graph
67e435dHEAD →main Cover the leche flan with foilba04ca2Add lumpiang shanghai recipe98a5edcAdd a script that builds the index paged078487Make the sinigang steps clearer145dc1eAdd pancit bihon recipe52d1f4dSay how much salt goes in the adobo1c17fadAdd a README9c53888Add leche flan recipe1f359a2Add sinigang recipe601c654Add adobo recipe
Version numbers
Many projects name release tags with semantic versioning: v1.4.2 is MAJOR.MINOR.PATCH.
- PATCH goes up for fixes: a typo in a recipe.
v1.4.2→v1.4.3. - MINOR goes up for new things that don't break anything: a new recipe.
v1.4.3→v1.5.0. - MAJOR goes up for changes that break what people relied on: renaming every file, so old links stop working.
v1.5.0→v2.0.0.
The "v" is a habit, not part of the standard. Simple Software Development 7.4 goes further into versions and releases.
Spot the trap: expecting a tag to follow
Ana tagged v1.0 last week. Since then she’s fixed two typos. She tells Lola Remy: “Print v1.0, it has the fixes.”
What happens if…
Check what you learned
Sources
Every command on this page behaves as these pages describe, and the sandbox prints what Git 2.55 prints. Hosting features (pull requests, protected branches) come from the host’s own documentation.
- Git documentation: git-tag: lightweight and annotated tags, and why release tags should be annotated
- Pro Git: Tagging: making, showing and sharing tags
- Git documentation: git-push, --tags: tags aren't pushed unless you ask