Does git clone copy every branch on the remote repository?
Is it possible to request it to clone some branches but not some other branches, just like git fetch does via its refspec argument?
Does git clone copy every branch on the remote repository?
Is it possible to request it to clone some branches but not some other branches, just like git fetch does via its refspec argument?
Remember that git clone, like all the rest of Git, doesn't really concern itself all that much with branch names, but rather with commits. It's just that Git (and git clone) needs names in order to find commits.
The git clone command itself essentially consists of:
git init in that directorygit remote add to save the URLgit fetch using the remote just addedgit checkoutHence, the question really boils down to: Can you control the fetch = setting for the remote that git clone adds?
The answer is Yes, but only to a limited extent. The limits are:
--mirror sets the refspec to +refs/*:refs/*.--bare sets the refspec to +refs/heads/*:refs/heads/* and +refs/tags/*:refs/tags/*.--single-branch or any of the commands that imply it set the refspec as appropriate for that operation.In the absence of either of these, you get a standard refspec. Hence, --single-branch lets you pick one branch to clone (by changing to a single-branch refspec), and --mirror lets you go outside the refs/heads/ namespace, but there is, at least as of today, no argument(s) that will do some intermediate subset. You can, instead, do your own mkdir / git init / git remote add / git config / git fetch / git checkout sequence of commands, if you wish to achieve some special result.