How to clone a specific Git branch ?

How to clone a specific Git branch ?

Asked on December 20, 2018 in Git.
Add Comment


  • 3 Answer(s)

    Here your following solution;

    And the difference is: by invoking git clone –branch <branchname> url you’re fetching all the branches and checking out one for instance, mean that your repository has a 5kB documentation or wiki branch and 5GB data branch and you want to edit your frontpage, you may end up cloning 5GB of data.

    git clone –branch is not the way to accomplish asking about cloning a specific branch.

    git clone --single-branch --branch <branchname> host:/dir.git
    

    –single-branch option, but let’s preserve it for full satisfaction

    git init
    git remote add -t refspec remotename host:/dir.git
    git fetch
    
    Answered on December 20, 2018.
    Add Comment

    Here your simple  code:

    git clone -b <branch> <remote_repo>
    

    Example:

    git clone -b my-branch [email protected]:user/myproject.git
    

    Git 1.7.10 and later, add –single-branch to prevent fetching of all branches e.g.  OpenCV 2.4 branch:

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

     

     

    Answered on December 20, 2018.
    Add Comment

    Clone a branch without fetching another branches:

    mkdir $BRANCH
    cd $BRANCH
    git init
    git remote add -t $BRANCH -f origin $REMOTE_REPO
    git checkout $BRANCH
    
    Answered on December 20, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.