Resolve Pr Conflicts
ASecurityResolve a pull request's merge conflicts by rebasing the PR branch onto its base, so the PR can land later with a rebase merge and a linear history. Use when the user says 'resolve conflicts in such a way that we can rebase to merge later', 'fix the merge conflicts on #N', 'the PR is conflicting' or 'dirty', 'make sure the PR is up to date', 'refresh, rebase, or update this PR on main', 'keep it rebase-mergeable', or when a merge fails with 'the merge commit cannot be cleanly created' and a s...
- 45 stars
- 0 votes
- 0 copies
- 1 view
- Added December 1, 2026
Works with
Security analysis
92/100- Installs packages at runtime which could introduce malicious dependencies
Pro scans all 5 files and shows the line behind each finding
npx -y skills add ericmjl/skills --skill resolve-pr-conflicts --agent claude-codeAre you the author of Resolve Pr Conflicts?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/ericmjl-resolve-pr-conflicts)---
name: resolve-pr-conflicts
description: "Resolve a pull request's merge conflicts by rebasing the PR branch onto its base, so the PR can land later with a rebase merge and a linear history. Use when the user says 'resolve conflicts in such a way that we can rebase to merge later', 'fix the merge conflicts on #N', 'the PR is conflicting' or 'dirty', 'make sure the PR is up to date', 'refresh, rebase, or update this PR on main', 'keep it rebase-mergeable', or when a merge fails with 'the merge commit cannot be cleanly created' and a stacked PR goes CONFLICTING after its parent merges. Surveys the cause read-only, rebases in a scratch checkout, resolves each conflict by the PR's intent, proves that every commit and change survived, force-pushes with a lease pinned to the old head, and confirms MERGEABLE on GitHub. Never merges the base into the branch (no merge commits) and never merges the PR itself (gh-cli)."
license: MIT
---
# Resolve PR conflicts so the PR can rebase-merge
Rebase a pull request branch onto the tip of its base branch, resolve the
conflicts that follow, and publish the result, so that GitHub offers a
rebase merge and the base branch stays linear.
One question drives every step: *after the rebase, does the PR still change
exactly what it changed before, on top of today's base?* GitHub's conflict
flag does not show that. A comparison of the commits and content before and
after the rebase does.
## Usage
Use this skill when a PR cannot merge because its branch is out of date.
- "Resolve conflicts in such a way that we can rebase to merge later."
- "Fix the merge conflicts on #N." "#N is conflicting."
- "We've recently merged some PRs, so make sure the PR is up to date."
- "Refresh this PR." "Rebase it on main." "Keep it rebase-mergeable."
- "Merge them all", and one PR fails with "the merge commit cannot be
cleanly created".
- A stacked PR turns `CONFLICTING` right after the PR below it merged.
Inputs you should accept:
- PR number, URL, or branch. Default: the PR for the current checkout.
- The base branch. Default: the PR's base branch on GitHub.
## Requirements
- `git` 2.38 or newer, for the read-only merge test
- `gh`, authenticated, with push access to the PR's head branch
- A checkout of the repository, and room for a scratch worktree
- The repository's checks, run on the rebased tree: lint, typecheck, the
tests for the changed files, any changelog validator
- This skill's two scripts, in `scripts/`, run from a checkout of the
repository
## What it does
Seven steps: **survey** → **prepare** → **rebase** → **resolve** → **verify**
→ **push** → **confirm and report**. Only the push changes anything that
other people can see.
Three facts explain most conflicts:
- **GitHub offers a merge, by any method, only when a plain three-way merge
of the head into the base is clean.** So a conflicting PR also blocks
`gh pr merge --rebase`, and GitHub's own error says so: "the merge commit
cannot be cleanly created". The fix is a rebase of the branch, then a push.
- **A rebase merge gives the PR's commits new SHAs on the base.** A PR that
is stacked on that branch still carries the old SHAs. GitHub's merge test
counts those commits as conflicts, although their content is already on the
base. A plain `git rebase` drops them, and the rebased tree is then
identical to the old one.
- **Bots move text on the base.** Release automation moves changelog entries
out of the unreleased section. A rebase can then merge a file without a
conflict and still put the PR's entry in the wrong place. "No conflict" is
not "correct".
## How it works
### Step 1 — Survey, read-only
Change nothing in this step.
```bash
gh pr view <PR> --json number,title,state,isDraft,baseRefName,headRefName,headRefOid \
mergeable,mergeStateStatus,reviewDecision,commits,statusCheckRollup
bash scripts/pr_conflict_survey.sh --base origin/<base> --head origin/<head> \
--pr <PR> --repo <owner/repo>
```
The script prints four things:
- The base, the head, and their merge-base.
- The head's commits, with a `-` on each one that the base already has by
content.
- The files that both sides changed.
- A dry-run merge, which is the test that GitHub runs. The script exits 0
when that merge is clean and 1 when it conflicts.
Read the output, then classify the PR:
| Survey says | Cause | Route |
| ----------- | ----- | ----- |
| Dry run conflicts, and both sides edited the same lines | A real conflict | Steps 2 to 7 |
| Dry run conflicts, and the head's commits are marked `-` | A stacked PR whose parent merged | Steps 2 to 7; expect a pure replay |
| Dry run clean, but the head is behind the base | Out of date only | Steps 2 to 7, with nothing to resolve. `gh pr update-branch <PR> --rebase` also works |
| `mergeable` is `UNKNOWN` | GitHub is still computing | Wait a few seconds and ask again |
| The head branch belongs to a bot, such as dependabot | The bot owns the branch | Comment `@dependabot rebase` and stop; see `gh-cli` |
| The head is on a fork you cannot push to | No push access | Stop; give the author the rebased patch or the recipe |
| Two valid behaviors conflict, and the choice is a product call | Not a text conflict | Describe both options to the user and stop |
Record three values for the rest of the run:
```bash
git fetch origin "+refs/heads/<head>:refs/remotes/origin/<head>" "+refs/heads/<base>:refs/remotes/origin/<base>"
OLD_HEAD="$(git ls-remote origin "refs/heads/<head>" | cut -f1)" # live, not the tracking ref
NEW_BASE="$(git rev-parse "origin/<base>")"
OLD_BASE="$(git merge-base "$NEW_BASE" "$OLD_HEAD")" # where the PR forked
```
### Step 2 — Prepare
- **Work in a checkout that nothing else uses.** Another session can switch
branches in a shared checkout in the middle of a rebase. Use a scratch
worktree, and confirm the branch before every command.
```bash
SCRATCH="$(mktemp -d)/pr-<PR>"
git worktree add --detach "$SCRATCH" "$OLD_HEAD"
cd "$SCRATCH" && git switch -c "rebase-pr-<PR>" && git branch --show-current
```
- **Keep an undo path.** The old head stays reachable from `OLD_HEAD` and
from the reflog. Name it in a local branch as well:
`git branch "backup/pr-<PR>" "$OLD_HEAD"`.
- **Set `GIT_EDITOR=true` for every rebase command.** Without a terminal,
`git rebase --continue` opens an editor and hangs.
- **Write down the rule for each conflicted file before you resolve it.**
For example: "the PR's changelog entry goes under `[Unreleased]`, and the
base's new release section stays as it is". A rule written first is a
decision. A rule written while staring at the markers is a guess.
### Step 3 — Rebase
```bash
git rebase "$NEW_BASE"
```
Git replays each commit of the PR in order. It drops a commit whose change is
already on the base ("skipped previously applied commit") and stops at the
first commit that conflicts.
- **Stacked PR after a squash merge.** The squash changed the parent's patch,
so git cannot recognize it. Replay only the PR's own commits:
`git rebase --onto "$NEW_BASE" <old-tip-of-the-parent-branch>`.
- **Never merge the base into the branch.** No `git merge`, no `git pull`, no
GitHub "Update branch" button, and no `gh pr update-branch` without
`--rebase`. Each one adds a merge commit to the PR branch.
- **Keep the commit list one to one.** Do not squash, reword, or reorder. The
reviewers approved those commits.
### Step 4 — Resolve each stop
At each stop:
```bash
git status --short # UU marks the unmerged files
git diff # the conflict, with both sides
git show :1:<file> # the common ancestor
git show :2:<file> # ours: the base branch, during a rebase
git show :3:<file> # theirs: the PR commit being replayed
```
During a rebase, **ours is the base and theirs is the PR**. That is the
opposite of a merge, and picking a side by name is the most common mistake.
Resolve by intent. The PR's change must survive on top of the base's newer
code.
| The conflict is in | Resolve it this way |
| ------------------ | ------------------- |
| A changelog or release notes | Keep the base's file. Put the PR's entry back in the unreleased section, never under a version the base released. Run the repository's changelog check. |
| A sorted list or registry (contributors, imports, an index) | Keep both sides, in the file's order, with no duplicates. Parse the file after the edit. |
| A row or line that the PR's own commits rewrote more than once | At each stop, take the incoming commit's version of that line, and keep the base's other lines. The same conflict stops each later commit that touches the line. |
| A lockfile | Regenerate it: `pixi lock`, `npm install --package-lock-only`, `uv lock`. Do not merge it by hand. |
| A generated file (types, a table of contents, a build) | Resolve the source, then regenerate the file. |
| A rename on one side and an edit on the other | Apply the edit in the renamed file, and keep the rename. |
| A file added on both sides | Merge both intents, and check that nothing from either side is missing. |
| A file deleted on one side and edited on the other | Decide from evidence: did the base replace it, or does the PR still need it? |
| Code | Read both changes. The base's rename, new signature, or new check applies to the PR's new code too. Then run the tests. |
Then continue:
```bash
git add <resolved files>
GIT_EDITOR=true git rebase --continue
```
Repeat until `git status` is clean and `git log --oneline "$NEW_BASE"..HEAD`
lists the PR's commits.
- **A clean auto-merge can still be wrong.** When the rebase finishes without
a stop, read every file that both sides changed. If the PR's entry landed
under a released version, move it in a new commit on top. When the PR's
commit list must stay as it was, put the fix in the commit that added the
entry instead (see [references/recipes.md](references/recipes.md)).
- **Skip a commit only when it is provably empty.** `git rebase --skip` is
right when the base already contains that exact change. Record the commit
you skipped and why.
- **Stop when a resolution needs a decision that is not yours.** Leave the
rebase as it is, describe the two options, and ask. `git rebase --abort`
returns the branch to `OLD_HEAD`.
### Step 5 — Verify
Prove the rebase before anyone sees it.
```bash
bash scripts/verify_rebase.sh "$OLD_BASE" "$OLD_HEAD" "$NEW_BASE" HEAD
```
The script runs six checks. It confirms that the new head sits on the new
base. It pairs every old commit with its rebased counterpart by patch. It
looks for conflict markers, compares the old and new trees, and compares the
PR's change file by file. Last, it checks the checkout for a rebase that is
still in progress. It ends with one verdict:
- **PASS.** The tree is identical to the old head. The rebase was a pure
replay.
- **REVIEW.** Content differs, which is what a real conflict resolution does.
The listed files and commits must be exactly the ones you resolved by hand.
Anything else is a mistake.
- **FAIL.** Do not push. The head is behind the base, a commit is missing,
markers remain, or a rebase is still in progress.
Then run the repository's checks on the rebased tree: lint and formatting,
the typecheck, the tests for the changed files, and the full suite when the
conflict was in code. A validator that passes proves little on its own. Run
it once more on a known-bad input, built as a commit that is on no branch,
and confirm that it rejects that one.
Last, read the PR's whole diff once more: `git diff "$NEW_BASE"`. Confirm
that each change the PR claims is still there. A text resolution can revert
the PR's own fix while removing the markers.
### Step 6 — Push with a lease
The push rewrites the PR branch, and it is the only destructive step here.
**The request covers the push** when the user named this PR and asked to
resolve, refresh, update, or merge it. Push in the same turn once Step 5
passes. **Ask first** in three other cases:
- You picked the PR yourself, as in triage, a stack, or a batch.
- The branch is not the user's own.
- Reviewers approved specific commits, and the user has not seen what the
rebase will change.
In those cases, verify first, then show the plan with the exact command.
```bash
git push --force-with-lease="refs/heads/<head>:$OLD_HEAD" origin "HEAD:refs/heads/<head>"
```
- **Pin the lease to the full old SHA**, read from `git ls-remote` in Step 1.
A bare `--force-with-lease` compares with the local tracking ref, which a
background fetch can refresh without notice, and `--force` checks nothing.
- **If the lease fails, the remote moved.** Someone pushed to the branch
while you worked. Fetch, read the new commits, and rebase again on top of
them. Never repeat the push with a weaker lease.
- **Push to the PR branch only.** Never force-push the base branch.
### Step 7 — Confirm on GitHub, then report
```bash
for i in 1 2 3 4 5 6 7 8 9 10; do
STATE="$(gh pr view <PR> --json mergeable,mergeStateStatus,headRefOid,commits \
--jq '"\(.mergeable)/\(.mergeStateStatus) head=\(.headRefOid[0:8]) commits=\(.commits|length)"')"
case "$STATE" in UNKNOWN*) sleep 5 ;; *) break ;; esac
done; echo "$STATE"
gh pr checks <PR>
```
- **`MERGEABLE/UNSTABLE`** means the conflict is gone and checks are running
on the new head. **`CLEAN`** means they passed. **`CONFLICTING`** after the
push means the rebase missed something: go back to Step 5.
- **`BLOCKED`** is not a conflict. A required review or check is missing, and
that belongs to the merge, not to this skill.
- **The commit count and the "Files changed" tab** should show the PR's own
commits and files only.
- **Wait for CI or report its state.** Never call the PR ready while a check
is pending or failing on the new head.
- **Post on the PR when others wait on it**: the base it was rebased onto,
the old and new head, each conflict and its resolution, and the checks you
ran. A template is in [references/report-example.md](references/report-example.md).
- **List the PRs stacked on this branch** (the survey prints them). Each one
now carries stale commits and needs the same treatment, bottom-up. See
`stacked-pr-decomposition` for the order and for the branch-deletion trap.
- **Hand off the merge.** Merging follows `gh-cli`: rebase merge only, pinned
to the head you verified, on the user's go-ahead.
Report the outcome first, then the evidence:
1. **Verdict.** Rebase-mergeable now, or not, and why.
2. **What moved.** PR URL, base and its SHA, old head, new head.
3. **Conflicts.** One line per file: what both sides did and what you kept.
4. **Verification.** The script's verdict, the checks and their results, and
anything you could not check.
5. **What remains.** CI state, reviews that a rebase invalidated, stacked
PRs, and the undo: `git push --force-with-lease="refs/heads/<head>:<new-head>" origin "<old-head>:refs/heads/<head>"`.
6. **Cleanup.** Remove the scratch worktree. Keep the backup branch until the
PR merges. Finish with a clean `git status`.
## Rules
- Rebase the PR onto the base. Never merge the base into the PR.
- Survey read-only first, and name the cause before you touch anything.
- During a rebase, ours is the base and theirs is the PR.
- Resolve by the PR's intent. Write the rule for each file before the markers.
- Regenerate lockfiles and generated files. Do not merge them by hand.
- Keep the commit list one to one. Skip a commit only when it is provably empty.
- "No conflict" is not "correct". Read every file both sides changed.
- No push before the verdict is PASS or an explained REVIEW.
- Pin the lease to the old head's full SHA. Never `--force`.
- The PR is done when GitHub says `MERGEABLE` on the new head, not when the
rebase ends locally.
- The merge belongs to `gh-cli` and to the user.
## What went wrong before
Each row is a failure from a past run, and the rule that it produced.
| What happened | What was missing | Do this instead |
| ------------- | ---------------- | --------------- |
| GitHub reported `CONFLICTING` right after the parent PR merged, with identical content | The child still had the parent's commits under their old SHAs | Rebase; git drops them, and the tree stays identical. Prove it with the verify script |
| The rebase was clean, and CI then rejected the changelog | Git had placed the PR's entry under a version that the base released since the fork | Read every file both sides changed; keep the entry under the unreleased section |
| "Keep both sides" at every stop left three versions of one row | The PR's own commits had rewritten that row in three steps | Take the PR's final version of the line; check the counts against the base |
| Fixing a misplaced changelog entry inside its own commit stopped the rebase again at every later commit that edited the entry | Each later commit's diff expected the entry in the old place | Resolve each stop the same way: that commit's wording of the entry, placed in the unreleased section |
| `git rebase --continue` hung, or failed with "Terminal is dumb, but EDITOR unset" | No editor in an agent shell | `GIT_EDITOR=true git rebase --continue` |
| A merge commit appeared on the PR branch | `gh pr update-branch` or the "Update branch" button was used without `--rebase` | Rebase locally, or pass `--rebase` |
| `gh pr merge --rebase` refused with "the merge commit cannot be cleanly created" | GitHub tests a plain merge before it offers any method | Rebase the branch and push; then merge |
| The lease was pinned to the local tracking ref, and it did not protect anything | A background fetch had refreshed that ref | Read the old head from `git ls-remote` and pin the lease to that SHA |
| Edits landed on `main` in the middle of a rebase | Another session switched branches in the shared checkout | Work in a scratch worktree; confirm the branch before each command |
| The markers were gone and the PR's own fix was gone too | The resolution took the base's behavior for that block | Re-read the PR's diff after the rebase; run its tests |
| After the rebase, the PR's new CI job pinned an old action version, and a formatter reflowed one line | No comparison with the base's current jobs, and no formatting run | Run the repository's formatter, and compare action pins and runner labels with the base's other jobs |
| Deleting a merged stack's branch closed the PR above it | The upper PR was not moved to `main` first | Move every stacked PR to the main base before deleting a branch |
| The PR branch belonged to dependabot | The bot owns the branch and overwrites edits | Comment `@dependabot rebase` |
## Related skills
- `gh-cli` — the merge policy (rebase only) and the merge itself, once the
user says go. Also owns the dependabot rebase.
- `stacked-pr-decomposition` — rebuilding a whole stack, the order to merge
it in, and the recovery when a branch deletion closed a stacked PR.
- `issue-pr-triage` — finds the PR that needs this. Its "update an existing
PR" path ends here.
- `prove-work-done` — the proof of the PR's behavior, which a rebase makes
stale. Re-run it on the new head before anyone merges.
- `pr-review` — reviews the diff. A resolution that changed code deserves a
second look.
Files in this skill
- SKILL.md
- references/recipes.md
- references/report-example.md
- scripts/pr_conflict_survey.sh
- scripts/verify_rebase.sh
Attribution
Related skills
View all in tools →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.