Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clone a specific Git tag

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?

like image 351
Jiang Jun Avatar asked Nov 29 '13 07:11

Jiang Jun


People also ask

Can you git clone a specific branch?

There are two ways to clone a specific branch. You can either: Clone the repository, fetch all branches, and checkout to a specific branch immediately. Clone the repository and fetch only a single branch.


2 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.

like image 94
Erik Saunier Avatar answered Oct 11 '22 11:10

Erik Saunier


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 
like image 43
Sahil kalra Avatar answered Oct 11 '22 10:10

Sahil kalra