Download a specific tag using Git
This article explains how to clone a repository at a specific tagged version. Git tags mark an important milestone in code production.
If you have a remote repository with tags and want to know how to clone that repository and access a specific tag, this post can meet your needs.
Download a specific tag using Git
For simpler context, we will use an example to illustrate this concept.
Assuming the following diagram represents the tags of the remote repository, how do we clone the repository of v0.0.4 ?
There are several ways to do this. You can use the git clone command or a combination of the git clone
and git checkout
commands.
Let's git clone
start with commands.
git clone command
We can pass the tag as an argument to the git clone command to clone and detach our HEAD to move it to the commit at the v0.0.4 tag. Here is an example.
$ git clone -b v0.0.4 https://github.com/user/repo.git
We can create a new branch for this tag by running the command below.
$ git checkout -b Dev
git checkout command
Alternatively, we can clone the repository and move our HEAD ref to the v0.0.4 tag.
To clone the repo, we will run:
$ git clone https://github.com/user/repo.git
Once the clone is complete, we can move HEAD to the v0.0.4 commit as shown below.
$ git checkout tags/v0.0.4
This will switch us into detached HEAD mode. We can run git checkout
the command to create a new branch based on our tag.
$ git checkout -b newbranch
This can be condensed into a single command as shown below.
$ git checkout tags/v0.0.4 -b newbranch
In summary, the methods discussed above end up cloning the entire Git repository. One is an alias of the other.
Your choice depends on your preference, as both methods accomplish the same thing.
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Git diff shows diff details of uncommitted changes
Publish Date:2025/03/31 Views:105 Category:Git
-
This article outlines how we can get diff details of uncommitted work in Git. We use the git diff command to show the differences between various Git references, such as commits, the index, and the working tree. We can use this command to d
Staging area in Git
Publish Date:2025/03/31 Views:151 Category:Git
-
In this article, we will learn about the staging area in Git . Git is a version control system that maintains a history of changes made to a project directory. Git uses commits to track changes. Git has three internal management systems, on
Add all files in a folder to commit in Git
Publish Date:2025/03/31 Views:158 Category:Git
-
This article will discuss the necessary steps to add all of your files into one folder for submission. If you have a folder with a dozen files, adding the files one by one can be tedious. Fortunately, Git allows us to add all the contents o
Meaning of Fetch_Head in Git
Publish Date:2025/03/31 Views:64 Category:Git
-
This article defines Fetch_HEAD in Git . This reference is an integral part of the git pull command and is important when merging changes from a remote repository into a local repository or branch. If you're not sure what Fetch_Head means,
Get all branches in Git
Publish Date:2025/03/31 Views:62 Category:Git
-
This article discusses how to fetch all branches from a remote repository. The git fetch command is a useful utility when you want to download changes from a remote repository without having to update your local branches. Sometimes, you may
Clone a Git repository with a specific revision
Publish Date:2025/03/31 Views:82 Category:Git
-
This article discussed various methods that we can use to clone a Git repository with a specific revision or changeset. This comes in handy when you have a repository with large files and you only need a specific version of the code. Instea
Squash commits pushed in Git
Publish Date:2025/03/31 Views:86 Category:Git
-
This article outlines the process of squashing commits that we have pushed to a remote repository. We squash the commits into one to reduce clutter in the repository. To squash the commits, we run git rebase in interactive mode . Squash com
Git squash all commits
Publish Date:2025/03/31 Views:65 Category:Git
-
In every developer’s life, the word squash is often used while working with the Git distributed control system . This feature in Git is a handy option that developers often use to achieve a neat workflow in their development team. In this
Close the Git commit editor on Windows
Publish Date:2025/03/31 Views:62 Category:Git
-
In this article, we will discuss how to exit the Git commit editor. This can be a little tricky, especially if you are new to Git bash . Let's see how to exit the editor on Windows. Close the Git commit editor on Windows We will look at a t