Combine prs

From drn/dots · View interactive version

Combine prs is an AI agent skill from the GitHub repository drn/dots. Compare two competing PRs implementing the same feature, identify strengths of each, and combine the best parts into a single branch. Use when comparing PRs, combining implementations, cherry-picking between PRs, or resolving competing approaches.

How to use this skill

Skill file

Arguments

If no arguments are provided, ask the user for two PR numbers.

Context

Your task

Compare two PRs that implement the same feature, analyze strengths and weaknesses, present a comparison, and on approval combine the best parts into one branch.

Step 1: Parse arguments and fetch PR metadata

Extract two PR numbers from the arguments (strip any leading "#" characters). If branch names are given instead, find their associated PRs via gh pr list.

For each PR, fetch metadata:

gh pr view <number> --json number,title,body,headRefName,baseRefName,author,state,additions,deletions,changedFiles

Verify both PRs target the same base branch and address the same feature. If they do not appear related, warn the user and ask whether to proceed.

Step 2: Fetch and analyze both diffs

For each PR, get the full diff:

gh pr diff <number>

Also read the actual changed files from each branch to understand full context (not just diff hunks). Check out each branch temporarily or use git show <branch>:<file> to read files without switching.

Analyze each PR across these dimensions:

Step 3: Present comparison table

Present a structured comparison to the user:

## PR Comparison: #<A> vs #<B>

| Dimension | #<A> | #<B> | Verdict |
|-----------|------|------|---------|
| Files changed | ... | ... | ... |
| Lines +/- | ... | ... | ... |
| Package placement | ... | ... | ... |
| Code liveness | ... | ... | ... |
| Test coverage | ... | ... | ... |
| Error handling | ... | ... | ... |
| API design | ... | ... | ... |
| Future implications | ... | ... | ... |

## Recommended Combination Strategy

Take from #<A>:
- ...

Take from #<B>:
- ...

Resulting branch: #<winner> (will be updated, #<loser> will be superseded)

Wait for the user to approve, modify, or reject the strategy before proceeding.

Step 4: Combine onto one branch

After user approval:

  1. Determine the surviving PR. Use whichever branch has the better foundation (or whichever the user specified). Check it out.
  1. Reset to base. Soft-reset to the merge base so all changes become staged:
git checkout <surviving-branch>
git reset --soft <base-branch>
  1. Unstage everything so you can selectively apply the combined result:
git reset HEAD .
  1. Apply the combined changes. Read the relevant files from both branches using git show <branch>:<file> and write the combined version that incorporates the best parts of each. This requires judgment — it is not a mechanical merge. For files where both PRs made changes:
  1. Stage and commit with a descriptive squashed commit message:
git add <files...>
git commit -m "$(cat <<'EOF'
<concise summary of the combined feature>

Combined from #<A> and #<B>:
- From #<A>: <what was taken>
- From #<B>: <what was taken>
EOF
)"
  1. Force-push with lease to update the surviving PR:
git push --force-with-lease origin <surviving-branch>

Step 5: Update PR descriptions

Update the surviving PR body to note the combination:

gh pr edit <surviving-number> --body "$(cat <<'EOF'
<original or updated description>

---
Supersedes #<other-number>. Combined the best of both implementations:
- From #<other>: <what was taken>
- From this PR: <what was kept>
EOF
)"

Step 6: Handle the superseded PR

Ask the user whether to close the superseded PR. If approved:

gh pr close <other-number> --comment "Superseded by #<surviving-number>, which combines the best parts of both implementations."

If the user declines, leave it open but add a comment noting the relationship:

gh pr comment <other-number> --body "See #<surviving-number> for a combined implementation that incorporates the best of both PRs."

Step 7: Report

Summarize what was done:

## Combined PR Result

- **Surviving PR:** #<number> (<url>)
- **Superseded PR:** #<number> (<status>)
- **Commit:** <short-sha> - <message>
- **From #<A>:** <what was taken>
- **From #<B>:** <what was taken>

Failure Handling

| Failure | Action |

|---------|--------|

| PR not found | Report and ask for correct number |

| PRs target different base branches | Warn user, ask to proceed |

| PRs are unrelated (no file overlap) | Warn user, ask to proceed |

| Merge conflicts during combination | Resolve manually, show user what was resolved |

| Force-push rejected | Report error, suggest git pull --rebase first |

| User rejects combination strategy | Ask what they want changed, revise the plan |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.