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?
There are two ways to clone a specific branch. You can either: Clone the repository, fetch all branches, and checkout to a specific branch immediately. Clone the repository and fetch only a single branch.
You can clone a specific branch from a Git repository using the git clone –single-branch –branch command. This command retrieves all the files and metadata associated with one branch. To retrieve other branches, you'll need to fetch them later on.
git clone -b <branch> <remote_repo>
Example:
git clone -b my-branch [email protected]:user/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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With