How to git clone and checkout only a branch

To git clone a specific branch without downloading the entire repository, do the following:

REPOSITORY=https://github.com/django/django
BRANCH=master
mkdir $BRANCH
cd $BRANCH
git init
git remote add -t $BRANCH -f origin $REPOSITORY
git checkout $BRANCH

This will download only the requested branch without fetching the full repository.

$ git branch --all
* master
remotes/origin/master
If you liked this posting, please feel free to leave me a comment below.
View this page on GitHub.
Posted .

Comments

Leave a Reply