Consider the following scenario:
F1---F2----M1----F3 (feature)
/ /
C1-----C2----C3 (main)
I want to rebase the feature branch, so they appear as commits added after main, but not merge it yet. The problem is, main was already merged (not rebased) in the past and those commits are now in feature too. I want the rebase to automatically skip the commits already present in main and feature.
This is what I want:
F1---F2---F3 (feature)
/
C1---C2---C3 (main)
And afterwards just merge normally with a merge commit like so
F1---F2---F3 (feature)
/ \
C1---C2---C3-------------M1---F1'---F2'---F3' (main)
It's a bit like in this question, but I don't want to merge. Just rebase and then force push in the branch itself.
Git rebase, skip merge-commits
EDIT:
I found out that the scenario is way more complex.
Consider three branches, feature1(F) feature2(G) and main(C).
S stands for squash, M for merge commit.
Current situation
main C1--------------S1
\ /
feature1 F1---F2---F3
\ \
feature2 G1---G2---M1---G3---G4
I want to rebase feature2 onto main but skip all commits from feature1, since they are already in main (as a squash) and also in feature2 (merged commits)