Level 9

Tag

Tag commits to mark important points in your history, and remove a tag you no longer need.

If branches are section markers that move forward as you add pages, then tags are sticky bookmarks you use to highlight special pages. Both point at a specific page in your scrapbook. The difference is that markers slide forward as new commits are made, while tags stay fixed on the commit where you placed them.

Step 1 of 6
0 xp

Milestones

Teams often use tags to mark important milestones, like version numbers. When a team is ready to release new software, they might bookmark the latest page in the main storyline with a name like v1.0 or v0.2.

git tag <tag> <commit>

Leave out the commit and Git bookmarks the page HEAD is on.

Bookmark the current page

Place your own bookmark on the latest page:

Type this into the terminal below
git tag v0.2

Nice one. You are truly TAG-nificent. A yellow tag appears on the most recent commit. Because you did not say which page to bookmark, Git placed it on the page HEAD was sitting on.

safe creates tag 'v0.2' pointing at HEAD; nothing is discarded.

An older page

You can also bookmark earlier pages, to highlight a past milestone. To name one, count back from HEAD: HEAD~2 means "the page two behind the one where HEAD sits".

Two pages back from the merge page is the page where Your Friend added friend.py. That feels like a v0.1 if ever there was one.

Bookmark an older page

Bookmark it as v0.1:

Type this into the terminal below
git tag v0.1 HEAD~2

Sweet. Another tag appeared, stuck on an earlier commit further back in the chain. Commit again later and the branch markers move on; both bookmarks stay exactly where you put them.

safe creates tag 'v0.1' pointing at HEAD~2; nothing is discarded.

Peeling one off

And if you decide you no longer need a bookmark? git tag -d <tag> removes it, and only it. The page underneath is untouched.

One more thing while we are here: git push sends branches, not tags. Push a tag by name, git push origin v0.1, or all of them with git push --tags. Almost everyone is surprised by this once. Consider yourself un-surprised in advance.

Your turn: peel one off

v0.2 was premature. Which command removes that bookmark and nothing else?

git-sim
Initial CommitDevlands

The graph appears here when the first command runs. The simulations are drawn by git-sim from a real repository.

The scrapbook · one picture for every Git idea

The scrapbook picture appears as the story is told.