There are two kinds of subsets you can specifiy during git clone
:
-b branchname --single-branch
allows you to only get those parts of the history that directly lead up to branchname
. It will skip everything not necessary to fully describe branchname
.
--depth n
allows you to truncate history beyond a certain depth.
Aside from that, clone
(as well as commit
, push
, pull
, merge
) and so on always by design process the whole directory tree starting at the root. The commit
(object) is the item they work with, they do not know about individual files (as opposed to CVS or SubVersion, for example, which can and regularly do work on individual files).
There are some ways to work with specific files/directories, but those are rather lowlevel and probably not what you want. For example, you can use the git protocol to fetch individual git objects (commits, trees, blobs...) directly... but I feel that's not what you are asking for.
Update: if you want to just grab the file and ignore the history, then you can use --depth 1
(to get the whole directory tree, but just for a single commit), grab your files, and be done with it. You still would need to download a lot more than you need, but at least it will be magnitudes less than the whole history (for something large like the Linux kernel).
Update 2: I am pretty sure that, except for doing your own implementation of the git networking protocol, there is no way to fetch single bits and pieces from a remote with the git commands. If you talk the protocol yourself, it's (relatively) easy of course. http://git-scm.com/book/en/v2/Git-Internals-Transfer-Protocols describes it, and it does not seem outlandish hard to use it yourself.