Tour of Git
Advanced Git / Lesson 5.2

git tag — Marking Milestones

Tags are permanent bookmarks in your Git history. They mark specific commits as important — typically for releases, versions, or milestones.

Two Types of Tags

Lightweight Tags

A lightweight tag is just a name pointing to a commit. Think of it as a branch that never moves.

git tag v1.0

Annotated Tags

An annotated tag is a full Git object. It stores the tagger's name, email, date, and a message. Use these for releases.

git tag -a v1.0 -m "First stable release"

Listing and Inspecting Tags

git tag              # list all tags
git tag -l "v1.*"    # list tags matching a pattern
git show v1.0        # show tag details and the tagged commit

Tagging Past Commits

You can tag any commit, not just the current one:

git tag -a v0.9 -m "Beta release" abc1234

Pushing Tags

Tags are not pushed by default. You must push them explicitly:

git push origin v1.0       # push a single tag
git push origin --tags      # push all tags

Deleting Tags

git tag -d v1.0                    # delete locally
git push origin --delete v1.0      # delete from remote

Try it!

Practice creating and managing tags:

  1. Initialize a repo and make some commits: git init && echo "v1" > app.txt && git add app.txt && git commit -m "First feature"
  2. Add more work: echo "v2" >> app.txt && git add app.txt && git commit -m "Second feature"
  3. Create a lightweight tag on the current commit: git tag v0.2
  4. Create an annotated tag: git tag -a v0.2.1 -m "Release candidate"
  5. Tag the first commit: git tag -a v0.1 -m "Initial release" HEAD~1
  6. List all tags: git tag
  7. Inspect the annotated tag: git show v0.2.1

When to Use Tags

  • Releases — v1.0.0, v2.1.3 (use annotated tags)
  • Deploy markers — deploy-2024-01-15 (lightweight is fine)
  • Milestones — beta, rc1, stable

Tags make it easy to check out any release: git checkout v1.0 puts you at exactly that point in history.

🎯

Goal

Create both a lightweight and an annotated tag

Terminal
$

No commits yet. Run `git init` and create your first commit.