How does one clone a git repository with only a non-master branch?
In cases where you don’t want to download unneeded files.
2 Solutions collect form web for “How does one clone a git repository with only a non-master branch?”
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
I’m not sure what you really want but another option is to clone with the
-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
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>