To list all tags in a Git repository, use git tag — it prints every tag in alphabetical order. For more detail, git tag -n shows the first line of each tag’s message, and git tag -l 'pattern*' filters by name.
What Are Git Tags?
Tags are pointers to specific commits, like branches that never move. They’re most often used to mark release points — v1.0, v2.3.1, or release-2024-05 — so you can always return to exactly that version of the code. Unlike branches, tags don’t advance when you make new commits; they stay fixed to the commit you tagged.
There are two types of tags:
- Lightweight tags — just a name pointing at a commit. Created with
git tag <tagname>. - Annotated tags — stored as full objects with a message, tagger name, email, and date. Created with
git tag -a <tagname> -m "message".
Annotated tags are recommended for releases because they carry metadata and can be signed. Lightweight tags are fine for temporary markers.
Basic Tag Listing Commands
The most common ways to list tags:
git tag— lists all tags alphabetically.git tag -lorgit tag --list— same as plaingit tag, but allows patterns.git tag -n— shows tags with their message (first line). Add a number like-n3to show more lines.git tag -l 'v1.*'— lists tags matching a pattern (e.g., all v1.x tags).git tag --sort=-creatordate— lists tags sorted by creation date, newest first.
If you want to see which commit a tag points to, use git show <tagname> — it displays the commit details, message, and changes.
Filtering Tags by Pattern
Patterns use shell wildcards. The -l flag makes filtering explicit:
git tag -l 'v2.*' # all tags starting with v2.
git tag -l '*rc*' # all tags containing 'rc'
git tag -l 'release-*'
This is useful when a project has dozens or hundreds of tags. You can combine with --sort to get a filtered, ordered list.
Sorting Tags
By default, git tag sorts alphabetically. To sort by date or version, use --sort:
git tag --sort=-creatordate— newest first.git tag --sort=creatordate— oldest first.git tag --sort=v:refname— version sort (treats numbers numerically).
Version sort is handy for tags like v1.9 and v1.10 — alphabetical would put v1.10 before v1.9 because “1.1” < “1.9”. Version sort correctly orders them.
Tags vs. Branches and Remotes
Tags are local by default. When you clone a repository, you get all tags that exist on the remote, but new tags you create locally are not pushed automatically. To push a tag: git push origin <tagname>. To push all tags: git push origin --tags.
To list tags on a remote without fetching them locally, you can use git ls-remote --tags origin. This shows the tag names and the commit hashes they point to, straight from the remote.
If you want to see tags that are not on any branch (dangling tags), you can use git fsck --no-reflogs --unreachable | grep tag — but this is rare and usually indicates a deleted tag.
Common Problems and Fixes
Problem: I don’t see tags that exist on the remote. Make sure you’ve fetched them: git fetch --tags. Cloning normally brings all tags, but if you’ve added a remote later, you may need to fetch.
Problem: I want to see tags with dates and authors. Use git tag -n for messages, or git show <tagname> for full details. For a formatted list with dates, try git for-each-ref --sort=creatordate --format='%(refname:short) %(creatordate:short)' refs/tags.
Problem: I accidentally deleted a tag. If it was pushed, you can recreate it from the remote: git tag <tagname> origin/<tagname> (after fetching). If it was local-only, you can recover it from the reflog only if you know the commit hash.
Problem: I want to list tags that contain a specific commit. Use git tag --contains <commit>.
Frequently Asked Questions
How do I list tags with dates?
Use git for-each-ref --sort=creatordate --format='%(refname:short) %(creatordate:short)' refs/tags. This shows each tag name and its creation date in YYYY-MM-DD format.
How do I list tags that match a pattern?
Use git tag -l 'pattern*'. For example, git tag -l 'v1.*' lists all tags starting with v1. The pattern is a shell glob, so * matches any characters.
Why does git tag show tags in alphabetical order by default?
That’s the default behavior for readability. You can override with --sort to sort by date or version. For version-sort, use git tag --sort=v:refname.
How do I list tags on a remote repository?
Use git ls-remote --tags origin. This contacts the remote and lists all tags without downloading them to your local repo. Replace origin with your remote’s name.
How do I see the message of a tag?
Use git tag -n to see the first line of each tag’s message. For the full message, use git show <tagname>.
Can I list tags that point to a specific commit?
Yes, use git tag --contains <commit-hash>. This lists all tags that have that commit as an ancestor.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- DisplayPort vs HDMI: Which Cable Should You Use?
- Soundbar vs 2.1 Speaker System: Which Is Better?
- Mouse Moving on Its Own? Causes & Fixes
- Slack Channels for Construction Projects: Setup Guide
- Surface Won’t Turn On: Quick Fixes1.8 h
- Survive Lava for Brainrot Tier List170 points