Sub topic 8
Conflicts and what rebase and merge cannot do on the web
This chapter assumes you can read git log --graph, resolve a conflict locally, and have met the three merge methods in earlier chapters. It covers how conflicts show up for each method and why "Rebase and merge" on GitHub has limits that a local git rebase does not.
How conflicts appear in a pull request
A conflict means the head branch and the base branch changed the same lines. GitHub disables the merge button and shows "This branch has conflicts that must be resolved." The check is made against the method you pick, so a pull request can be mergeable with one method and blocked with another.
For merge commit and squash, Git does one three-way merge. All the branch's changes are compared with the base once, so you resolve each conflicting region once.
For a rebase, Git replays commits one at a time. If commits 1 and 3 both touch the same lines that changed on main, you may resolve conflicts several times, once per replayed commit. This is the main reason a long branch is painful to rebase.
What "Rebase and merge" does on GitHub
GitHub replays each commit of the head branch onto the tip of the base branch and then fast-forwards the base branch. Three details matter:
- Every replayed commit gets a new SHA, because its parent changed. The commits on your branch and the commits on
mainare different objects with the same content. - The committer becomes the person who clicked merge. The author is kept.
- Signatures are lost. A commit you signed locally is not signed by you after replay, so GitHub signs the new commits itself or leaves them unsigned.
What the web interface cannot do
The web editor can resolve conflicts for merge commit and squash. It cannot do so for a rebase.
GitHub's conflict editor produces a merge of the base into your branch. That is a different operation from replaying your commits. So when a pull request can't be rebased cleanly, the button is disabled for rebase and GitHub tells you to rebase locally. The same applies if the rebase would need any manual step.
The other limits:
- You cannot choose the commits to replay or edit, reorder, or drop them, as in
git rebase -i. - You cannot change commit messages during the merge.
- A merge commit in the branch's history is not preserved. The replay produces a flat sequence.
- A rebase merge may fail even when a merge commit would succeed, because the replayed sequence can conflict where the single merge does not.
Resolving a rebase conflict locally
git fetch origin
git switch feature
git rebase origin/main
# Git stops at the first conflicting commit. Edit the files, then:
git add path/to/resolved-file
git rebase --continue
# Repeat until the rebase finishes, then:
git push --force-with-leaseIf the result looks wrong, git rebase --abort returns the branch to its state before the rebase started.
After the push, GitHub recalculates mergeability and the rebase button becomes available again.
Comparing the methods
| Situation | Merge commit | Squash | Rebase and merge |
|---|---|---|---|
| Conflict resolution in the web editor | Yes | Yes | No |
| Number of times you resolve the same lines | Once | Once | Up to once per commit |
| Original commit SHAs kept | Yes | No | No |
| Fails when other methods succeed | Rarely | Rarely | Yes, more often |
Common mistakes
- Merging
maininto the branch to fix a conflict, then expecting a rebase merge to keep that merge commit. The replay drops it. - Using
--forceafter a local rebase and erasing a teammate's commit. - Assuming a green "can be merged" status for squash applies to rebase too.
Exercise
A pull request shows no conflicts when you choose "Squash and merge", but "Rebase and merge" is greyed out. Give one reason this can happen and what you do to enable it.
Show answer
Rebase replays commits one at a time, so an individual commit can conflict with the base even when the combined change merges cleanly. The web editor cannot resolve this. Run git rebase origin/main locally, resolve each conflict with git add and git rebase --continue, then git push --force-with-lease.