How to checkout a Git tag

Checking out a tag puts you in a detached HEAD state, which is fine for inspecting a release but not for committing. If you want to make changes, create a branch from the tag.

Mark van Eijk 1 minute read Development
  1. Checkout a tag
  2. You are now in detached HEAD
  3. Make changes from a tag: create a branch
  4. The tag is missing?

Checkout a tag

A tag points at a specific commit, usually a release. Check it out by name:

git checkout v1.2.0

To be unambiguous (in case a branch and a tag share a name), use the full ref:

git checkout tags/v1.2.0

You are now in detached HEAD

After checking out a tag, Git warns you that you are in a detached HEAD state. That means HEAD points directly at a commit instead of a branch. You can look around, build, and run the code, but any commits you make here are not on a branch and will be lost once you switch away.

Make changes from a tag: create a branch

If you need to work from a tagged release, for example to patch an old version, create a branch from the tag:

git checkout -b hotfix-1.2.0 v1.2.0

The modern equivalent uses git switch:

git switch --detach v1.2.0      # just inspect
git switch -c hotfix-1.2.0 v1.2.0  # branch off the tag

The tag is missing?

If git checkout v1.2.0 fails with pathspec ... did not match, your clone probably does not have the tag yet. Fetch tags from the remote:

git fetch --tags

List the tags you have to confirm the exact name:

git tag