Fetch and check out a specific Git tag

Fetch a Git tag, make a shallow clone or source archive, preserve detached commits, and verify the revision used for deployment.

Best practices
Illustration of Git history and collaboration

Fetch the tag, then check it out in detached HEAD mode to inspect or build its commit. If you intend to make changes, create a branch from that commit.

Fetch and check out one tag

Save or commit local work before changing checkouts. For a tag named v1.0.0 on origin:

git fetch origin tag v1.0.0
git show --no-patch v1.0.0
git switch --detach refs/tags/v1.0.0

To fetch all tags instead, use git fetch origin --tags. git tag --list shows local tag names. On an older Git version without switch, git checkout refs/tags/v1.0.0 also checks out the tag's commit.

Detached HEAD means the checkout points directly to a commit rather than a local branch. You can read and build the code. New commits remain reachable through HEAD while you stay there, but a branch gives them a durable name before you switch away.

Make a shallow clone at a tag

git clone --depth 1 --branch v1.0.0 https://github.com/ORG/REPO.git

Replace the repository and tag. This creates a Git repository with shallow history at that tag and normally leaves HEAD detached. It is not a source-only download. Branch names are also accepted by --branch; verify that you selected the intended tag if a project uses ambiguous names. See git-clone.

For a source archive without Git history, GitHub provides archives for tags:

curl --fail --location --output source-v1.0.0.tar.gz \
  https://github.com/ORG/REPO/archive/refs/tags/v1.0.0.tar.gz
tar -tzf source-v1.0.0.tar.gz
tar -xzf source-v1.0.0.tar.gz

Inspect and extract the archive in a suitable directory. A source archive is not necessarily a ready-to-run release package, and it does not include the contents of submodule repositories. Check the project's build instructions and assets.

Keep work made from the tag

While still at the tag or a new detached commit:

git switch -c fix-on-v1.0.0

This attaches the current commit to a new branch. If you already switched away, inspect git reflog, identify the correct commit, and create a branch at that ID. Recovery depends on the commit still being available; a reflog is not a permanent backup.

Common questions

Why does Git say the tag cannot be found? Verify the remote, exact spelling, and your access. git ls-remote --tags origin lists visible remote tags. Fetch the specific tag again. A GitHub Release title may differ from its tag name, and a network or permission failure is not proof that the tag does not exist.

Does deploying a tag guarantee a reproducible release? A tag identifies a commit, but tags can be moved unless repository controls prevent it. Record the resolved commit ID, verify signatures when required, and pin the build inputs. Dependencies, submodules, generated files, and environment differences can still change the artifact.

Can I return to a normal branch? After saving any new work, use git switch main or the appropriate existing branch. Changing the checkout does not itself delete a tag.

References

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting