Use the --onto argument to git rebase, which changes the baseline that git replays work on.
git checkout branch0
At this state you should still see C in your git history.
git rebase --onto B' C
This translates to: Take all commits in my current branch since commit C (In your case that’s just D) and play back on top of B’
You can also use the optional <branch> argument to do both the checkout and rebase at once:
git rebase --onto B' C branch0