Given a git situation like this:
A---B---X---C'---Y (main)
\
C---D---E (my-branch)
I want
A---B---X---C'---Y---D'---E' (my-branch)
Note that main has C' which is the same commit as C, but rebased onto X (possibly with some fixups)
99% of the time I can just type git rebase main
from my-branch and it works great, telling me it noticed that C has already been applied and that it skipped the commit.
But sometimes it has conflicts reapplying C so instead of fixing them I proceed with:
git rebase --abort
git checkout main
git branch -D my-branch
git branch my-branch
git cherry-pick C..E
git push -u origin my-branch --force-with-lease
And it works with fewer conflicts. However, it's 5 commands instead of 1, requires deleting a branch, requires hunting down git SHA's and requires a force push. It has a significant potential for screwing up my branch.
Is there a better way to do this that is less error prone?