Git clone will clone remote branch into local.
Is there any way to clone a specific branch by myself without switching branches on the remote repository?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
--single-branchoption is valid from version 1.7.10 and later.Please see also the other answer which many people prefer.
You may also want to make sure you understand the difference. And the difference is: by invoking
git clone --branch <branchname> urlyou’re fetching all the branches and checking out one. That may, for instance, mean that your repository has a 5kB documentation or wiki branch and 5GB data branch. And whenever you want to edit your frontpage, you may end up cloning 5GB of data.Again, that is not to say
git clone --branchis not the way to accomplish that, it’s just that it’s not always what you want to accomplish, when you’re asking about cloning a specific branch.