Back

Explore Courses Blog Tutorials Interview Questions
+3 votes
2 views
in DevOps and Agile by (19.4k 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

+4 votes
by (27.5k 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

+4 votes
by (29.3k 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

Browse Categories

...