Branches · lesson 6 of 7
Commands and ideas in this lesson
Agit taglist tags, or make a lightweight one
Bgit tag -a v1.0 -man annotated tag, with a message
Cv1.2.0version numbers

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
  1. 67e435d HEAD →main⚑ birthday-print Cover the leche flan with foil
  2. ba04ca2 Add lumpiang shanghai recipe
  3. 98a5edc Add a script that builds the index page
  4. d078487 Make the sinigang steps clearer
  5. 145dc1e Add pancit bihon recipe
  6. 52d1f4d Say how much salt goes in the adobo
  7. 1c17fad Add a README
  8. 9c53888 Add leche flan recipe
  9. 1f359a2 Add sinigang recipe
  10. 601c654 Add adobo recipe
1 of 3 Ana tags today’s commit 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.0 shows 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

Git sandbox
  1. Make a lightweight tag birthday-print on the newest commit
  2. Make an annotated tag v1.0 with the message “First printed edition”
  3. Make an annotated tag v0.1 on the first commit, “Lola’s first three recipes”
  4. Show v1.0 and compare it with git show birthday-print
  5. Make a new commit, then check with git log --oneline that 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

  1. 67e435d HEAD →main Cover the leche flan with foil
  2. ba04ca2 Add lumpiang shanghai recipe
  3. 98a5edc Add a script that builds the index page
  4. d078487 Make the sinigang steps clearer
  5. 145dc1e Add pancit bihon recipe
  6. 52d1f4d Say how much salt goes in the adobo
  7. 1c17fad Add a README
  8. 9c53888 Add leche flan recipe
  9. 1f359a2 Add sinigang recipe
  10. 601c654 Add 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

Spot the trapAna

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

What is the difference between a branch and a tag?
Which kind of tag should mark a release?
Kusina is at v2.3.1. Ana adds a new recipe, changing nothing else. What’s the next version?

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.

All sources for Simple Git