This tutorial will help you to clone a specific git branch from the remote git repository via command line.
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 <BRANCH_NAME> <GIT_REMOTE_URL>
The following command will clone the branch 5.1-branch from the WordPress git repository.
git clone -b 5.1-branch https://github.com/WordPress/WordPress.git
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.
You can use
--single-branch to prevent fetching details of other branches like below:
git clone -b 5.1-branch --single-branch https://github.com/WordPress/WordPress.git
All done. You can view the currently active branch by running the command: