How do I clone a single branch in Git?

后端 未结 21 2591
再見小時候
再見小時候 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:41

    There are primarily 2 solutions for this:

    1. You need to specify the branch name with -b command switch. Here is the syntax of the command to clone the specific git branch.

      git clone -b  
      

      Example:

      git clone -b tahir https://github.com/Repository/Project.git
      

      The following command will clone the branch tahir from the git repository.The above command clones only the specific branch but fetches the details of other branches. You can view all branches details with command.

      git branch -a
      
    2. You can use --single-branch flag to prevent fetching details of other branches like below:

      git clone -b  --single-branch 
      

      Example:

      git clone -b tahir --single-branch \ 
      https://github.com/Repository/Project.git
      

      Now if you do a git branch -a, it will only show your current single branch that you have cloned and not all the branches. So it depends on you how you want it.

提交回复
热议问题