Data report"State of code review 2024" is now liveRead the full report

How to check out 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.


Checking out tags in Git allows you to switch your working directory to the state of the codebase at the time the tag was created. Tags are often used to mark release points (e.g., v1.0, v2.0), making it easy to switch between different versions of the code. This guide will walk you through how to checkout specific tags, work with remote tags, and various other operations related to Git tags.

Stop wrestling with Git commands

The Graphite CLI takes all the pain out of Git, allowing you to ship faster and stop Googling Git commands.

Learn more

Before checking out a tag, it’s helpful to now which tags exist in the first place.

First run:

Terminal
git fetch --tags

This will fetch all available tags from the remote, allowing you to see the full list of tags available to you.

In order to see a list of all of the existing tags in your repo run:

Terminal
git tag

In order to search for specific tags you can also apply a shell wildcard pattern match with the -l flag:

Terminal
git tag -l <pattern>

This will output a list of all the tags that match the supplied pattern. If you supply multiple patterns, the command will output a list of all tags that match any of these patterns.

  • Git checkout tag: To checkout a tag, use the git checkout command followed by the tag name:

    git checkout <tag-name>

    This command switches your working directory to the state of the specified tag.

  • Git checkout a tag as new branch: If you want to make changes starting from a tag, it's best to checkout the tag into a new branch:

    git checkout -b <new-branch-name> <tag-name>

  • Git checkout tag from remote: To checkout a tag that exists in the remote repository but not locally, first fetch the tags:

    git fetch --tags

    Then, checkout the tag using the git checkout <tag-name> command.

  • Git checkout remote tag as branch: After fetching tags, you can create a new branch from a remote tag similarly to how you would with a local tag:

    git checkout -b <branch-name> <tag-name>

The best engineers use Graphite to simplify Git

Engineers at Vercel, Snowflake & The Browser Company are shipping faster and staying unblocked with Graphite.

Git started for free
  • Git checkout latest tag: To checkout the most recent tag, first fetch the tags from remote:

    git fetch --tags

    Then find the latest tag with a combination of the git describe and git rev-list commands. You can save this tag to a local variable for use in the next step:

    latestTag=$(git describe --tags $(git rev-list --tags --max-count=1))

    Once you have the latest tag, check out as normal using the variable we just created:

    git checkout $latestTag

  • Git Checkout tagged Version/branch/commit: These operations are fundamentally similar, as they involve checking out a specific state identified by a tag. Use the git checkout <tag-name> command for a version or commit, and if you want to start a new branch from a tagged commit, use git checkout -b <new-branch-name> <tag-name>.

  • Git checkout tag without detached HEAD: When you checkout a tag directly, Git puts your repository in a "detached HEAD" state. To avoid this, checkout the tag into a new branch:

    git checkout -b <new-branch-name> <tag-name>

    For further reading on this state, please see the guide on resolving a detached HEAD state.

  • Git checkout tag not working: If you encounter issues checking out a tag, ensure the tag exists (git tag) and that you have fetched the latest tags from the remote repository (git fetch --tags).

  • GitPython Checkout Tag: If you're using GitPython, a Python library to interact with Git repositories, you can checkout a tag programmatically:
Terminal
repo = git.Repo('<path-to-repository>')
git = repo.git
git.checkout('<tag-name>')
  • GitHub checkout specific tag: While GitHub does not have a direct "checkout" feature in the web UI, you can clone the repository locally and then checkout the tag using the command line tools as described above.

For further reading please see the official git documentation on tagging.

Stay unblocked. Ship faster.
Experience the new developer workflow - create, review, and merge code continuously. Get started with one command.
Learn more

Give your PR workflow
an upgrade today

Stack easier | Ship smaller | Review quicker

Or install our CLI.
Product Screenshot 1
Product Screenshot 2