Sub topic 8
Conflicts and What Rebase and Merge Cannot Do on the Web
This chapter assumes you can read git log --graph output, have merged a pull request on GitHub, and know what a merge conflict looks like in a file. It covers why conflicts show up differently for each merge method, what the web interface can and cannot fix, and how to resolve the rest locally.
Why the merge method changes the conflict
A conflict happens when two branches change the same lines, or one side changes a file the other deleted or renamed. GitHub checks for conflicts before it enables the merge button. The check depends on the method you pick.
- Merge commit: Git does one three-way merge. It compares the tip of the head branch, the tip of the base branch, and their common ancestor. You resolve each conflicted file once.
- Squash and merge: The result is also one three-way comparison, of the branch's combined changes against the base. Intermediate commits do not matter, so a conflict that existed only in the middle of the branch never appears.
- Rebase and merge: Git replays each commit of the branch, one at a time, on top of the base. Each replay can conflict on its own.
The last point has a practical consequence. A pull request can be mergeable with a merge commit or a squash and still fail to rebase.
Suppose commit 1 of your branch edits config.yml in a way that conflicts with main. Commit 2 then rewrites the same lines again. The final tree may merge cleanly, because commit 2 overwrote the conflicting region. Replaying commit 1 still stops at a conflict.
What rebase and merge does on the web
When you choose rebase and merge, GitHub replays every commit of the head branch onto the base branch. It then moves the base branch to the last replayed commit. The result is linear, with no merge commit.
GitHub does this even when the base branch has not moved. A plain git rebase followed by a fast-forward would keep the original commits. GitHub always writes new commits with new SHAs. The consequences:
- Authorship: The author of each commit stays the same.
- Committer: The committer field is updated. It no longer names the original committer.
- Signatures: Do not rely on original commit signatures surviving. Verify how your organization's signature requirements behave with this method before you adopt it.
- CI results: Checks ran against the old SHAs, not the new ones. The code is the same only if the base did not change in between. If you need checks on the exact merged result, require the branch to be up to date before merging.
- Messages: You cannot edit commit messages at merge time. Every commit goes in as written, including "fix typo" and "wip".
Compare the resulting SHAs yourself:
git fetch origin
git log --oneline origin/main -n 5
git log --oneline feature -n 5After a rebase and merge, the same commit subjects appear in both lists with different SHAs.
What the web cannot do for you
If a rebase fails, the pull request page shows that the branch cannot be rebased, and the rebase option is disabled. The web interface offers no rebase conflict editor. GitHub's Resolve conflicts button opens an editor that does something different. It merges the base branch into the head branch and records the result as a merge commit on the head branch.
This editor is limited:
- It only handles conflicts caused by competing line edits in text files.
- It does not handle a file deleted on one side and edited on the other.
- It does not handle renames, and it does not handle binary files.
- It cannot replay your commits one by one.
For those cases, and for any pull request you want to merge with rebase and merge, resolve locally.
| Situation | Web editor | Local resolution |
|---|---|---|
| Competing edits to the same lines of a text file | Yes, adds a merge commit to the head branch | Yes |
| File deleted on one side, edited on the other | No | Yes |
| Binary file changed on both sides | No | Yes |
| Conflict appears at an intermediate commit during rebase | No | Yes, one stop per commit |
| You want a linear history with no merge from base | No | Yes, rebase and force-push |
If you resolve with the web editor and then use rebase and merge, the merge commit you just created is not part of the final linear result. Check the outcome carefully. Git's default rebase drops merge commits and replays only ordinary commits. The conflict can then reappear in the replay.
Resolving a rebase conflict locally
This is the standard path when rebase and merge is blocked.
git fetch origin
git switch feature
git rebase origin/mainGit stops at the first commit that conflicts and lists the files. Open each file, remove the conflict markers, and keep the correct content. Then continue:
git add path/to/conflicted-file
git rebase --continueRepeat until Git reports that the rebase finished. If you want out, git rebase --abort restores the branch to its state before you started.
Because a rebase rewrites the branch's commits, a normal push is rejected. Use a force push that refuses to overwrite work you have not seen:
git push --force-with-lease origin feature--force-with-lease fails if someone pushed to feature after your last fetch. Plain --force would overwrite their commits.
If the same conflict repeats across many commits, enable git rerere. It records how you resolved a conflict and reapplies the resolution on later replays.
git config rerere.enabled trueYou can also avoid the long conflict series by squashing the branch locally first. Run git rebase -i origin/main, mark all but the first commit as squash, and resolve the conflict once.
Updating the branch from the web
The Update branch button on a pull request can bring the head branch up to date with the base. Its dropdown offers two choices:
- Update with merge commit: Adds a merge commit to the head branch. History is preserved and nobody's local copy breaks.
- Update with rebase: Replays the head branch onto the base and rewrites the head branch history. Anyone who has the branch checked out must reset to the new tip.
Both options work only when there are no conflicts. Once conflicts exist, you are back at the web editor or a local resolution.
Consequences for team settings
Conflict handling is a reason to review which methods you allow. If you enable only rebase and merge, contributors must be comfortable with local rebases and force pushes. Otherwise a routine conflict blocks the pull request. If you enable squash or merge commits as well, a contributor who cannot rebase can pick another method. Choose deliberately; do not leave this to chance.
You can check from the command line whether a pull request is currently mergeable:
gh pr view 123 --json mergeable,mergeStateStatusmergeable is MERGEABLE, CONFLICTING, or UNKNOWN. UNKNOWN often means GitHub has not finished computing the answer yet, so run the command again after a few seconds. A CONFLICTING value tells you only that some conflict exists. Use the pull request page to see which method is affected.
Merging with the CLI follows the same rules as the web:
gh pr merge 123 --rebaseIf the branch cannot be rebased, this command fails. It does not rebase locally for you.
Common errors
- "This branch cannot be rebased due to conflicts": The branch fails during replay. Rebase locally and force-push with lease.
- Resolve conflicts button is missing or grayed out: The conflict type is not editable on the web. Resolve it locally.
- Conflict returns after resolving on the web and using rebase and merge: The web resolution lived in a merge commit that the replay drops. Rebase locally instead.
- Push rejected after a local rebase: The branch history changed. Push with
--force-with-lease. - The same conflict appears at several commits: Enable
git rerereor squash the branch locally before rebasing.
Exercise
A pull request has three commits. Commit 1 changes line 10 of app.py in a way that conflicts with main. Commit 2 changes line 10 again, and the final file merges cleanly with main. Which merge methods will GitHub offer, and why?
Show answer
Merge commit and squash and merge are available, because each compares only the final result against main, and that result has no conflict. Rebase and merge is not available, because it replays commit 1 first, and that replay conflicts. To use rebase and merge, rebase locally, resolve the conflict at commit 1, and push with --force-with-lease.
Exercise
You resolved a conflict using the web editor, and the pull request now shows a merge commit from main in its history. Your repository allows only rebase and merge. Why might you still want to rebase locally, and what command pushes the result safely?
Show answer
Rebase and merge replays the branch's ordinary commits and does not keep the merge commit, so the web resolution may not carry over and the conflict can reappear during the replay. Rebasing locally with git rebase origin/main resolves it where it actually occurs. Push with git push --force-with-lease origin feature.