When working on a feature branch you should keep the branch up to date by rebasing on to your main branch.
You should also open a PR early, keeping it in a βDraftβ state.
But what happens if there is a force push to main while your branch is open. Well, your PR starts to look very busy, showing all the commits that are different to main. These often include commits that were not made by you.
So how can you fix it?
- Take a backup of your branch by renaming the feature branch to something like
backup/feature-name - Create a new
feature-namebranch, branching fromorigin/main - Cherry-pick the relevant commits from
backup/feature-nameonto the newfeature-namebranch. - Finally
force pushyourfeature-namebranch