How do I clone a single branch in Git?

后端 未结 21 2572
再見小時候
再見小時候 2020-11-22 00:09

I have a local Git repository called \'skeleton\' that I use for storing project skeletons. It has a few branches, for different kinds of projects:

casey@aga         


        
21条回答
  •  死守一世寂寞
    2020-11-22 00:39

    Using Git version 1.7.3.1 (on Windows), here's what I do ($BRANCH is the name of the branch I want to checkout and $REMOTE_REPO is the URL of the remote repository I want to clone from):

    mkdir $BRANCH
    cd $BRANCH
    git init
    git remote add -t $BRANCH -f origin $REMOTE_REPO
    git checkout $BRANCH
    

    The advantage of this approach is that subsequent git pull (or git fetch) calls will also just download the requested branch.

提交回复
热议问题