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-name
branch, branching fromorigin/main
- Cherry-pick the relevant commits from
backup/feature-name
onto the newfeature-name
branch. - Finally
force push
yourfeature-name
branch