← Back to Git Course | Chapter 2: Basic Commands | Lesson 9 of 18

Git tags Command

A tag is like sticking a bright flag on one page of the photo album to say 'this is version 1'. The flag always stays on that exact page and never moves.
Syntax
bash
git tag tag_name
git tag -a tag_name -m "tag message"
git tag -l "pattern"

Creating Lightweight Tags

A lightweight tag is just a named pointer to a specific commit, with no extra metadata of its own — essentially a branch that never moves. They're quick to create and fine for private, temporary bookmarks, but they lack the authorship and message info that a real release usually wants.

Example: Creating Lightweight Tags

bash
git tag v1.0

Creating Annotated Tags

An annotated tag (git tag -a v1.0 -m "message") is stored as a full object in Git's database, complete with the tagger's name, email, date, and a message — the same way a commit is. This is the recommended tag type for anything you'll actually publish as a release, since the extra metadata documents who cut the release and why.

Example: Creating Annotated Tags

bash
git tag -a v1.0 -m "Release version 1.0"

Listing and Searching Tags

git tag alone lists every tag in the repository, and git tag -l "v1.*" filters that list to a glob pattern — handy once a project has accumulated dozens of version tags and you only care about one release line.

Example: Listing and Searching Tags

bash
git tag
git tag -l "v1.*"

Deleting Project Tags

git tag -d <name> deletes a tag locally, but since tags are pushed to a remote separately from commits, you also need git push origin --delete <name> (or :refs/tags/<name>) to remove it from the shared remote — otherwise it just reappears the next time someone fetches.

Example: Deleting Project Tags

bash
git tag -d v1.0
git push origin --delete v1.0

Sharing Tags on Remote Servers

Unlike commits and branches, git push does not upload tags by default, so a tag you create locally is invisible to collaborators until you explicitly push it with git push origin <tagname> or push all tags at once with git push --tags.

Example: Sharing Tags on Remote Servers

bash
git push origin v1.0
git push origin --tags
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Creating a tag and expecting it to be on the remote, when git push does not send tags and you need git push origin v1.0.
  2. Using a lightweight tag for a release when you want an author, date and message, which needs an annotated tag with -a.
  3. Tagging the wrong commit because you did not check which commit is HEAD, when you can tag a specific one with git tag v1.0 <hash>.

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.