How to clone a specific Git branch?

This question already has an answer here:

  • How to clone a single branch in git? 14 answers

  • git init
    git remote add -t refspec remotename host:/dir.git
    git fetch
    

    但是,如果我记得正确,默认情况下,克隆将从远程工作分支中提取所有分支,而不是当前工作分支。


    git clone -b <branch> <remote_repo>
    

    Example:

    git clone -b my-branch git@github.com:user/myproject.git
    

    Alternative (no public key setup needed):

    git clone -b my-branch https://git@github.com/username/myproject.git
    

    With Git 1.7.10 and later, add --single-branch to prevent fetching of all branches. Example, with OpenCV 2.4 branch:

    git clone -b opencv-2.4 --single-branch https://github.com/Itseez/opencv.git
    

    克隆一个分支而不需要获取其他分支:

    mkdir $BRANCH
    cd $BRANCH
    git init
    git remote add -t $BRANCH -f origin $REMOTE_REPO
    git checkout $BRANCH
    
    链接地址: http://www.djcxy.com/p/90456.html

    上一篇: 如何在Git中标记较旧的提交?

    下一篇: 如何克隆特定的Git分支?