In cases where you don't want to download unneeded files.
git clone
always clones the complete repository unless you specify the --depth <n>
parameter which limits the repository to the latest n revisions (a so-called “shallow clone”).
However, you can create a local repository and use git fetch
to only fetch parts of the remote repository.
cd /path/foo
git init
git remote add origin <some url>
git fetch origin <some branch>
This will duplicate most of what git clone
does but restrict it to the branch(es) you specify on the command line. (I’m not sure about further details such as tracking branches and tags and the like.)
Your question title and summary are kind of asking two different questions because, as Bombe noted, a clone always gets all content unless use use the --depth
option.
I'm not sure what you really want but another option is to clone with the --no-checkout
(or -n
) flag. By default, git
will checkout the default branch for the repository (which is determined by the HEAD
ref in the remote repository -- it's not always master
). If you use the -n
flag git
will not checkout a branch for you so you can just checkout what you want:
git clone -n <some url> foo
cd foo
git checkout <some branch>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With