From git-clone(1) Manual Page

--branch can also take tags and detaches the HEAD at that commit in the resulting repository.

I tried

git clone --branch <tag_name> <repo_url> 

But it does not work. It returns:

warning: Remote branch 2.13.0 not found in upstream origin, using HEAD instead 

How to use this parameter?

3

6 Answers

git clone --depth 1 --branch <tag_name> <repo_url> 

--depth 1 is optional but if you only need the state at that one revision, you probably want to skip downloading all the history up to that revision.

5

Use --single-branch option to only clone history leading to tip of the tag. This saves a lot of unnecessary code from being cloned.

git clone <repo_url> --branch <tag_name> --single-branch 
3
git clone -b 13.1rc1-Gotham --depth 1 Cloning into 'xbmc'... remote: Counting objects: 17977, done. remote: Compressing objects: 100% (13473/13473), done. Receiving objects: 36% (6554/17977), 19.21 MiB | 469 KiB/s 

Will be faster than :

git clone Cloning into 'xbmc'... remote: Reusing existing pack: 281705, done. remote: Counting objects: 533, done. remote: Compressing objects: 100% (177/177), done. Receiving objects: 14% (40643/282238), 55.46 MiB | 578 KiB/s 

Or

git clone -b 13.1rc1-Gotham Cloning into 'xbmc'... remote: Reusing existing pack: 281705, done. remote: Counting objects: 533, done. remote: Compressing objects: 100% (177/177), done. Receiving objects: 12% (34441/282238), 20.25 MiB | 461 KiB/s 
2
git clone --depth 1 --branch <tag_name> <repo_url> 

Example

git clone --depth 1 --branch 0.37.2

<tag_name> : 0.37.2 <repo_url> : 
1

Use the command

git clone --help 

to see whether your git supports the command

git clone --branch tag_name 

If not, just do the following:

git clone repo_url cd repo git checkout tag_name 

Cloning a specific tag, might return 'detached HEAD' state.

As a workaround, try to clone the repo first, and then checkout a specific tag. For example:

repo_url= repo_dir=$(basename $repo_url .git) repo_tag=0.5 git clone --single-branch $repo_url # using --depth 1 can show no tags git --work-tree=$repo_dir --git-dir=$repo_dir/.git checkout tags/$repo_tag 

Note: Since Git 1.8.5, you can use -C <path>, instead of --work-tree and --git-dir.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy