How does one clone a git repository with only a non-master branch?

git

Solution

`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.)

Problem

In cases where you don't want to download unneeded files.

Original source

Related problems