Git Clone Tag Guide

August 29, 2022

Introduction

Git tags are milestones in a project development history, such as patches, bug fixes, or new program versions. When debugging or developing a new feature, it is sometimes easier to clone those specific points than to clone an entire repository or development branch.

In this tutorial, you will learn to clone a Git tag.

Learn to clone a tag in Git.

Prerequisites

How to Clone a Specific Git Tag

Cloning a git tag requires a repository URL and running a specific command. Follow the steps below to clone a Git tag.

1. Obtain Git Repository URL

Log in to your GitHub account and select your repository. Click the Code button and copy the repository URL.

Obtain a repository's URL in GitHub.

Note: Learn also how to clone Git submodules.

2. Clone Git Tag

Use the following syntax to clone a particular tag:

git clone -b [tag_name] [repository_url]
  • Replace [tag_name] with the name of the tag you want to clone.
  • Replace [repository_url] with the repository link obtained in the previous step.

For example:

git clone -b v1.2 https://github.com/bosko-pnap/git-project.git

The command clones tag v1.2 from the specified repository URL.

Note: To download only the latest commit in the branch and reduce the download size, add the --depth 1 flag to the command.

After cloning the tag, Git states that the repository is in a detached HEAD state. The state occurs because the tag is in the middle of long commit history. Therefore, adding new commits can disturb the Git blockchain.

A detached HEAD still allows you to make and commit changes, but they don't update the repository. Instead, the changes create a new detached commit, which doesn't easily merge back to the master branch.

The detached commits don't belong to any branch, and they are only reachable directly by the commit's SHA hash. Resolve the detached HEAD state by creating and switching to a new branch before committing any changes.

Note: Git tags are objects, which means checkout works with Git tags as well. Follow our tutorial and see how to checkout a Git tag and resolve the detached HEAD state.

Conclusion

This tutorial showed how to clone a specific Git tag and resolve the detached HEAD state resulting from the tag cloning process.

For more Git tutorials, see how Git works or learn to work with Git Bash effectively.

Was this article helpful?
YesNo
Bosko Marijan
Having worked as an educator and content writer, combined with his lifelong passion for all things high-tech, Bosko strives to simplify intricate concepts and make them user-friendly. That has led him to technical writing at PhoenixNAP, where he continues his mission of spreading knowledge.
Next you should read
Git List Tags
August 25, 2022

Git tags are specific points in a project's development history. This tutorial shows how to list Git tags in a local and remote repository.
Read more
Git Push Tag to Remote Guide
August 17, 2022

Follow this guide to learn to create and push a single, multiple, or all local Git tags to a remote repository.
Read more
How To Delete Git Tag
August 15, 2022

Git tags mark particular points in a project's history. This tutorial shows how to delete a local and remote tag.
Read more
Git Create Tag Guide
August 10, 2022

Git tags denote specific points in a project's Git history. This tutorial shows how to create Git tags.
Read more
  • © 2022 Copyright phoenixNAP | Global IT Services. All Rights Reserved.