Git & GitHub · Chapter 22 of 42

Git Tags

A tag marks a specific commit as important, typically to mark release points like v1.0 or v2.1.0. Unlike branches, tags don't move — they point permanently to one commit.

Git supports lightweight tags (just a name pointing to a commit) and annotated tags (which store extra metadata like the tagger's name, date, and message).

Syntax
git tag v1.0
git tag -a v1.0 -m "message"
git push origin --tags

Creating tags

Use `git tag v1.0` for a lightweight tag, or `git tag -a v1.0 -m "Release version 1.0"` for an annotated tag with a message.

Listing and pushing tags

Run `git tag` to list all tags. Tags are not pushed automatically — use `git push origin tag-name` or `git push origin --tags` to push them to a remote.

Example 1 (bash)
git tag -a v1.0 -m "First stable release"

Creates an annotated tag named v1.0 with a message, pointing to the current commit.

Example 2 (bash)
git tag
git push origin --tags
Output
v1.0
...
To github.com:user/repo.git
 * [new tag]         v1.0 -> v1.0

Lists all local tags and pushes them all to the remote repository.

Key points

  • Tags mark specific commits, often for releases.
  • Lightweight tags are just names; annotated tags store extra metadata.
  • Tags don't move like branches do.
  • Tags must be pushed explicitly with git push --tags.
💡 Note: Use annotated tags for public releases since they store who created the tag and why.

📝 Quick Quiz

1. What are Git tags typically used for?

2. What is the difference between lightweight and annotated tags?

3. How do you push tags to a remote repository?