Skip to content
tools for techies
Colour theme

Split a PR

Breaks a big branch into a stack of small PRs and proves the stack matches the original.

Claude Code skill codemaman-pr-split, works with GitHub and Jira.

Small PRs, happy reviewers

Install it

Copies the skill into ~/.claude/skills:

curl -fsSL https://toolsfortechies.dev/install.sh | bash -s -- codemaman-pr-split

Or download the zip and unzip it into ~/.claude/skills. Restart Claude Code afterwards.

Try it

Ask Claude
“This PR is too big, split it into a stack”
Or run
/codemaman-pr-split

Before you start

You'll need
gh CLI signed in. Works with Graphite, git-town or spr if you use them.
What it won't do without you
Never touches the original branch. Ends with an empty diff against it as proof.
Read the SKILL.md
# Split a Large PR into Stacked PRs

Turn one big branch into a sequence of small PRs where each one builds, passes tests, and tells a single story. The original branch is never modified or deleted; the final stack must be byte-identical to it.

## 1. Preconditions
- Resolve the source branch and its base (default branch or PR base). Working tree must be clean; if not, stop and ask. Fetch and confirm the branch is up to date with its base (offer to merge/rebase base first, but don't rewrite published history without asking).
- Record the safety anchor: `git rev-parse HEAD` (the source tip) and create a backup ref `git branch backup/<branch>-presplit`.
- If the branch has an open PR with review comments, warn that splitting resets review context, and ask whether to keep it as the "umbrella" PR or close it later.

## 2. Analyse
- `git diff <base>...HEAD --stat` plus a read of the full diff and commit log. Group changes by purpose and dependency, for example:
  1. Pure refactors / renames / moves with no behaviour change
  2. Dependency, config, tooling, or CI changes
  3. Schema/migration changes and backfills
  4. Backend/domain logic and its tests
  5. API surface
  6. UI components, then pages wiring them up
  7. Docs and cleanup
- Respect dependencies: a PR can only use code already in earlier PRs in the stack. Identify shared types/utilities that must go first. Find unrelated drive-by changes and propose moving them to their own PR.
- Target size: ideally under ~400 changed lines and one idea per PR; 3-6 PRs is typical. Each PR must compile, lint and pass its own tests independently (feature flags or additive code help).

## 3. Propose the plan and get approval
Show a numbered table: PR title, purpose, files/hunks included, approx size, depends-on, how it stays green. Call out hunks that need splitting within a file, and risks (e.g. a test that only passes with a later PR). Wait for the user's approval or edits. Don't start until they agree.

## 4. Build the stack
For each slice in order, on a branch named `<original>-1-<slug>`, `-2-<slug>`, ...:
- Slice 1 branches from the base; slice N branches from slice N-1.
- Bring in only that slice's changes: `git checkout <source-branch> -- <paths>` for whole files. For partial files, interactive `git add -p` is not available, so generate a patch for the specific hunks and apply it with `git apply --cached`, or edit the file to the intended intermediate state. Prefer whole-file slicing by planning boundaries to match files where possible.
- Commit with a message that includes the Jira key and the purpose.
- Run the project's build, lint, typecheck and tests on every slice. If a slice fails, fix the slice boundary (move the missing piece earlier), not the test.

## 5. Prove nothing was lost
After the last slice: `git diff <last-slice-branch> <source-branch>` must be empty (or contain only differences the user approved, which you list). Report this result explicitly. If not empty, find the missing hunks and place them.

## 6. Open the PRs
With the user's OK, push each branch and open PRs with `gh pr create --base <previous-slice-branch>` (slice 1 targets the real base), titled `[1/N] ABC-123: <summary>`. Each description (use the codemaman-pr-description skill if available) must include: the stack list with links, "depends on #X", what this slice does and doesn't do, and how to test. Mark later slices as draft until their parent is approved. If the repo uses a stacking tool (Graphite, git-town, spr), prefer its commands.

- After the stack exists, comment on the original PR (if any) linking the new PRs, and ask before closing it.
- If Jira is connected, offer to add a comment with the stack links or create subtasks, after confirming exactly what you'll do.

## 7. Merge guidance
Tell the user the merge order, that merging slice 1 requires retargeting slice 2 to the base (GitHub does this automatically when the parent branch is deleted on merge), and that squash-merging parents means later slices need a rebase onto the base (`git rebase --onto <base> <old-parent> <slice-branch>`). Offer to do the rebases when the time comes.

## Rules
- Never delete, force-push or modify the original branch or its backup ref.
- Never push or open PRs without approval of the plan and a green result for each slice.
- If the change cannot be split cleanly (tightly coupled), say so and suggest the smallest honest split rather than forcing one.
Open the raw file

More skills like this