I am trying to clone multiple specific branches in a repository.
I know it is possible to clone one specific branch using --single-branch, but what if I want 2 specific branches and no other branch?
I know I can use git config remote.origin.fetch as shown here to change the regex of the "monitored" branches, but can I do this when I clone?
You cannot do this with git clone directly, but you don't need to.
Remember that git clone is short for doing git init, git remote add, git fetch, and git checkout (more precisely there are six steps but this is the gist). The git remote add command itself can add multiple single branches, while git clone cannot.
Hence, the two ways to go are:
git remote add yourselfgit remote set-branches origin each of the remaining branches (one per command or all at once).If you use the git remote set-branches method, remember to run git fetch again afterward.
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