Home

Git rebase --onto

February 17, 2022 - git

Squashed commits can pose a problem when there is a chain of branches, e.g.:

  1. branch-1 targets main, contains commit A
  2. branch-2 targets branch-1, contains commit A and commit B

Imagine that before merge, a subsequent commit is made in branch-1, so it is now A + C. Upon merge, this becomes A' on main because we use squash commits.

Now we have a problem: main has A' but branch-2 has A + B. It's a merge conflict!

The solution: git checkout branch-2 and git rebase --onto main branch-1.

More details here.