Read Anthropic’s case study about Graphite Reviewer

How to list Git tags

Greg Foster
Greg Foster
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


Tags in Git are pointers to specific commits. They are often used to mark release points (e.g., v1.0, v2.0) in the development cycle.

There are two types of tags in Git:

  • Lightweight tags: These tags are a simple pointer to a commit, bookmarking individual commits.
  • Annotated tags: These are stored as full objects in the Git database, which include the name of the tagger, email, date, and have a tagging message. Annotated tags can also be signed and verified with GPG (GNU Privacy Guard).

This guide will explore how to list and manage tags in Git, focusing on both local and remote tags, and how to synchronize tags between local and remote repositories.

To list all tags that are currently in your local repository (where Git stores data on your local machine), you can use the git tag command.

Terminal
git tag

This command will output a list of all tags in your repository, sorted in lexicographic order:

Terminal
v1.0
v1.1
v2.0

If you want to see more details about your tags, especially for annotated tags, you can use the git show command followed by the tag name:

Terminal
git show v1.0

This command displays the tag message, the commit it points to, the author, and the date of the commit:

Terminal
tag v1.0
Tagger: John Doe <john@example.com>
Date: Mon Feb 1 12:00:00 2021 -0400
Release version 1.0
commit 4a5b6c7d8e9f0g1h2i3j4k5l6m7n8o9p0q1r2s3
Author: John Doe <john@example.com>
Date: Sun Jan 31 11:59:59 2021 -0400
Initial release

While the above commands list your local tags, there may be other tags that exist on the remote server but that you do not yet have locally. These tags are referred to as "remote tags." Remote tags do not automatically transfer to your local repository when you perform git fetch or git pull. You need to explicitly fetch these tags from the remote.

To fetch all tags from your remote repository, you can use:

Terminal
git fetch --tags

This command will download all tags from the remote repository, along with the commits they point to.

To list tags that exist on a remote repository, use the git ls-remote --tags command followed by the remote's name (commonly origin).

Terminal
git ls-remote --tags origin

This command fetches a list of all tags from the specified remote without adding them to the local repository.

Terminal
3f6fc9d6521a2f8cfd1b3dc6c8e88f1ecf50674a refs/tags/v1.0
4a5b6c7d8e9f0g1h2i3j4k5l6m7n8o9p0q1r2s3 refs/tags/v1.1
5d6e7f8g9h0i1j2k3l4m5n6o7p8q9r0s1t2u refs/tags/v2.0

If you need to fetch all the tags along with their associated commits, use the git fetch command with the --tags option:

Terminal
git fetch --tags

This ensures that you have all the commits associated with the fetched tags, enabling you to check out or inspect the tags if needed.

For further reading on Git tags, see the official Git documentation.

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2