HOWTO · Git

How to Download a Specific Tag With Git

Learn how to download a specific tag with Git by cloning a repository at a specific tag version. This guide covers various methods, including cloning directly at a tag, checking out tags after cloning, and fetching all tags for easy navigation. Perfect for developers looking to work with precise code versions.

On this page

To work with a repository at a particular Git tag, clone the repository at that tag or move an existing clone to it. A tag names a specific commit, often a release. This task is different from git pull: pull integrates remote changes into the branch you currently have checked out.

Clone a repository at a specific tag

Use git clone --branch <tag_name> <repository_url>, replacing the placeholders with the tag and repository URL. The --branch option accepts either a branch or a tag. When you give it a tag, Git checks out that tagged commit in the new clone; it does not create a branch for you. A normal clone also fetches repository history, rather than limiting the download to the tagged snapshot.

Run this local example:

set -eu
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
git init --quiet "$tmpdir/source"
git -C "$tmpdir/source" config user.name "Example User"
git -C "$tmpdir/source" config user.email "example@example.com"
printf 'first version\n' > "$tmpdir/source/README.md"
git -C "$tmpdir/source" add README.md
git -C "$tmpdir/source" commit --quiet -m "Initial commit"
git -C "$tmpdir/source" tag v1.0.0
git -c advice.detachedHead=false clone --quiet --branch v1.0.0 "$tmpdir/source" "$tmpdir/checkout"
git -C "$tmpdir/checkout" describe --tags --exact-match
v1.0.0

This uses a temporary local repository so you can see the selected tag without relying on a remote service. Replace the local source path in a real command with the repository URL you want to clone.

Fetch and list tags in an existing repository

If you already have a clone and cannot find the tag, fetch tags from its remote with git fetch --tags origin. Substitute the remote name if yours is not origin. To display tags available locally, run git tag --list; add a pattern, such as git tag --list 'v2.*', to narrow the list. Fetching makes remote tags available locally, but does not change the branch or commit currently checked out.

A freshly created clone normally has its remote tags. Fetching is useful when the tag was added after your last fetch, or when the repository’s fetch settings do not include it. If the tag still does not appear, check its spelling and confirm that it exists on the remote.

Check out a tag in an existing clone

Once the tag is available locally, use git checkout <tag_name> or git checkout tags/<tag_name> to move the working tree to it. Replace the placeholder with the exact name shown by git tag --list. This changes the commit your working tree reflects, so save or commit any existing work before switching. Checking out a tag puts you at its commit with detached HEAD; it does not move the current branch to that commit.

Create a branch from a tag

To make new commits that are attached to a branch, create the branch at the tag with git checkout -b <new_branch_name> <tag_name>. For example, use git checkout -b maintenance-v1 v1.0.0 to start maintenance-v1 at tag v1.0.0. If you have already checked out the tag, git checkout -b <new_branch_name> creates a branch at the current commit. You can then commit normally, and the branch name keeps those commits reachable as you continue working.

Understand detached HEAD and clone behavior

A branch is a movable reference to commits; a tag normally stays attached to the commit it names. In detached HEAD, Git records the checked-out commit directly instead of naming a branch. It is useful for inspecting, building, or testing a release. You can switch back to a branch when finished, or create a branch first if you plan to commit work. Commits made while detached exist initially, but without a branch or another reference they can become difficult to find later.

Cloning at a tag selects that tag for the working tree; it does not create a branch and does not by itself make the clone shallow. For a deliberately shallow clone, add a depth option such as --depth 1 to git clone; this limits fetched history and is a separate choice from selecting a tag. Choose a full clone when you need history beyond the tagged commit, and create a branch from the tag when you need to keep new commits.