+4 votes
1 view
in Devops and Agile by (20k points)
edited by

Git clone will behave copying remote current working branch into local.

Is there any way to clone a specific branch by myself without switching branches on the remote repository?

2 Answers

+5 votes
by (28.4k points)

Use the following command to clone a specific branch by myself without switching branches on the remote repository:

git clone --single-branch --branch <branchname> host:/dir.git

+5 votes
by (29.1k points)
edited by

For shortened, you could see @debashis answer.

In git 1.7.10 it allows the user to clone a single branch using:

git clone --single-branch

as in:

git clone <url> --branch <branch> --single-branch [<folder>]

And since Git 1.9.0, shallow clones support data transfer (push/pull) using:

git clone --depth 1

so this option is even more useful now. And this is the easiest way to reduce the bandwidth.

Refer: 

https://git-scm.com/docs/git-clone#Documentation/git-clone.txt---depthltdepthgt

For more commands like this please go through the following tutorial that will help you understand the git

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...