Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I shallow clone a repo on a specific branch?

How do I shallow clone a git repository, so that my clone contains only 1 history item, and starts on a specific branch?

I know how to do a shallow clone:

git clone --depth 1 https://path/to/myrepo.git 

but not start the clone on a specific branch.

like image 502
joseph.hainline Avatar asked Feb 17 '14 16:02

joseph.hainline


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.

How do I clone a specific Github 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.

Can you clone only part of a repository?

At the moment it is not possible to clone only a single directory. But if you don't need the history of the repository, you can at least save on bandwidth by creating a shallow clone.


1 Answers

To clone repo foo.git with branch bar do:

git clone --depth 1 https://path/to/repo/foo.git -b bar 

See the git-clone documentation: https://www.kernel.org/pub/software/scm/git/docs/git-clone.html

like image 150
joseph.hainline Avatar answered Sep 22 '22 01:09

joseph.hainline