How to git clone a specific tag

Jiang Jun picture Jiang Jun · Nov 29, 2013 · Viewed 251.4k times · Source

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?

Answer

Erik Saunier picture Erik Saunier · Feb 11, 2014
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.