git clone and checkout in a single command

user2731584 picture user2731584 · Aug 30, 2013 · Viewed 28k times · Source

The following is the command I use to checkout a specific commit.

git clone git://repo.git/repo123
git checkout <commitID>

I want to do the above in one step - using a git clone command only.

The reason why I want to do this is, repo123 is very huge. So checking out the commit I want will save me a lot of time.

I am aware of --depth option. But in this case, it is of no use. Can anyone tell me how to do it?

Answer

jthill picture jthill · Sep 11, 2013
git clone u://r/l --branch x

still clones everything but sets the local HEAD to that branch so it's the one checked out.

Source:

--branch <name>
-b <name>
Instead of pointing the newly created HEAD to the branch pointed to by the cloned repository’s HEAD, point to <name> branch instead. In a non-bare repository, this is the branch that will be checked out. --branch can also take tags and detaches the HEAD at that commit in the resulting repository.