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.
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.
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.
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
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