Clone a specific tag with Git
This post will discuss how to clone a specific tag with Git.
1. git checkout
Here, the idea is to clone a repository using the git-clone command and then check out the specific tag using git-checkout.
$ git clone <repository> .
# switch to the specific tag
$ git checkout tags/<tagname>
This is demonstrated below:

Note, this will leave the repository in a ‘detached HEAD’ state. This means any commits you make in this state will not impact any branches. If needed, you can create a new branch using the -b option:
2. git clone
You can also check out the specific tag with git-clone. It has –branch option, which can also take tags and detaches the HEAD at that commit in the resulting repository.
This is demonstrated below:

If you only need the specific tag, you can pass the --single-branch flag, which prevents fetching all the branches in the cloned repository. With the --single-branch flag, only the branch/tag specified by the --branch option is cloned.
Alternatively, you can specify the --depth option, limiting the total number of commits to be downloaded to the specified depth. It implies --single-branch by default.
That’s all about cloning a specific tag with Git.
Thanks for reading.
To share your code in the comments, please use our online compiler that supports C, C++, Java, Python, JavaScript, C#, PHP, and many more popular programming languages.
Like us? Refer us to your friends and support our growth. Happy coding :)