Can you shallow clone 2 branches using git?

Viewed 332

I'd like to shallow clone part of a repository: just 1 feature branch (including all of the commits since branching from main) and a few commits on main before that.

I have tried git clone $repo --depth=N --branch=$feature which does correctly check out a shallow clone of $feature, and assuming I pick depth to be large enough goes back to the branch point.

What's the incantation to pull in main as well?

Essentially I want to be able to do:

git clone --branch=$feature
BASE=$(git merge-base $feature origin/main)
echo git rev-parse $BASE^
echo git rev-parse $BASE^^
echo git rev-parse $BASE^^^

to tell me the SHA1s of the few commits that happened just before branching.

0 Answers
Related