How To Fix: This branch cannot be rebased due to conflicts

Last updated 6th February, 2024

When this happens, I tend to fix it using a reset. This won't keep the individual commits, so if you need them - this solution isn't for you.

git checkout my-branch
git fetch
git merge origin/main
git reset --soft origin/main

# Here is your chance to add a meaningful commit message
# to replace the lost commits
git commit -va
git push -f origin/my-branch

In the above we:

  • Ensure our branch is up to date with the main branch
  • Reset the local branch to the main branch - without altering the working copy
  • Create a new commit to represent the merge. This is where you can specify what all of the squashed commits represent, in absense of the originals.
  • Finally, push the your remote branch

Hope this helps!

No comments yet…

DevInTheWild.

Login To Add Comments.

Want More Like This?

Subscribe to occasional updates.

Related Articles