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

Git tags Command

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

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.