Petr Petr - 2 months ago 20
Git Question

How to checkout remote branch with git clone --depth 1?

I downloaded last revision of a big repository, where I need to get a latest revision of one branch so that I can test it.

How do I do that?

When I did

git clone --depth 1 url
I got last revision of master and the branch doesn't seem to exist?

petanb@petrbena:~/Documents/mh$ git checkout flaggedrevs
error: pathspec 'flaggedrevs' did not match any file(s) known to git.

Answer

git clone --depth 1 implicitly carries a --single-branch option, which defaults to the primary branch, which is origin/master by default.

If you want to clone a different branch, tell git which one you want to clone.

git clone --depth 1 --branch <branch> url