3

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.

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
Steven Canfield
  • 7,312
  • 5
  • 35
  • 28
  • 2
    I think you would need to use the `git clone --depth=N --no-single-branch` option. – TTT Nov 19 '20 at 20:35
  • 1
    https://stackoverflow.com/a/46816633/7976758 Found in https://stackoverflow.com/search?q=%5Bgit%5D+shallow+clone+multiple+branches – phd Nov 19 '20 at 20:43

0 Answers0