Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I clone a specific Git branch? [duplicate]

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?

like image 776
Scud Avatar asked Dec 15 '09 23:12

Scud


People also ask

How do I clone only a specific branch?

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.

Can I duplicate a branch in git?

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.


1 Answers

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 
like image 165
Jorge E. Cardona Avatar answered Sep 22 '22 16:09

Jorge E. Cardona