Reputation: 6335
--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?
Upvotes: 605
Views: 714359
Reputation: 25
I recommend
git clone --depth 1 [email protected]:etlegacy/etlegacy.git --tags 2.80.2 --single-branch
Upvotes: -4
Reputation: 4294
git clone --depth 1 --branch <tag_name> <repo_url>
Example
git clone --depth 1 --branch 0.37.2 https://github.com/apache/incubator-superset.git
<tag_name> : 0.37.2
<repo_url> : https://github.com/apache/incubator-superset.git
Upvotes: 26
Reputation: 10510
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.
Upvotes: 1008
Reputation: 16990
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=https://github.com/owner/project.git
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
.
Upvotes: 3
Reputation: 9064
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
Upvotes: 148
Reputation: 4188
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
Upvotes: 8
Reputation: 3186
git clone -b 13.1rc1-Gotham --depth 1 https://github.com/xbmc/xbmc.git
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 https://github.com/xbmc/xbmc.git
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 https://github.com/xbmc/xbmc.git
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
Upvotes: 39