Home
cd ../playbooks
Developer ToolsIntermediate

Reshape PR Commits

Turn a branch's messy WIP/fixup commit history into a clean, logically-grouped set of commits before review — proposed regrouping with explicit approval, git reset --soft plus staged re-commits instead of interactive rebase, and hard guardrails (feature branches only, force-with-lease only, never touch another author's commits).

5 minutes
By Qualcomm (GenieX)Source
#git#pull-requests#commit-history#code-review#git-workflow

A PR with fifteen commits named 'wip', 'fix', and 'oops typo' works fine to merge, but it makes the diff impossible to review commit-by-commit and turns git blame into archaeology — and the fix isn't interactive rebase's fragile editor dance, it's a three-command reset-and-recommit flow any agent can run safely with the right guardrails.

Who it's for: developers who batch small WIP commits while working and need a clean history before opening a PR, tech leads who want reviewable, logically-grouped diffs instead of a stream-of-consciousness commit log, teams standardizing on conventional commit messages before merge, anyone nervous about force-pushing history rewrites

Example

"Clean up my commits before I open this PR" → git log against the merge-base to see the noisy history, the combined diff read to understand what actually changed (not what the messages claim), a numbered regrouping plan presented for approval before anything is touched, then git reset --soft plus staged re-commits and a force-with-lease push

CLAUDE.md Template

New here? 3-minute setup guide → | Already set up? Copy the template below.

Or install from your terminal:
npx ccplaybooks add reshape-pr-commits
# Reshape PR Commits

Turn the current branch's commit history into a set of commits that each represent one coherent logical change, with terse messages. Use when asked to tidy, squash, reshape, or clean up commits on the current branch or PR.

## Proactive Suggestion (When Not Explicitly Invoked)

When the user signals the PR is done — "done with this PR," "ready for review," "let's open the PR," or just before calling a PR-ready command — check `git log <base>..HEAD --oneline`. If the history is noisy (WIP/fixup/"oops" commits, or many tiny commits touching the same area), offer once: suggest cleaning up the commits before review. Accept either answer and move on; do not re-ask in the same session.

## Non-Negotiable Guardrails

- **Only ever rewrite the current feature branch.** Refuse if the branch is the main/default branch, or if the current HEAD is already merged.
- **Always `--force-with-lease`**, never plain `--force`, when pushing the rewritten history.

Get new playbooks like this one

One email a week with new Claude Code workflows. Free, like everything here.

No spam. Unsubscribe anytime.

README.md

What This Does

A disciplined workflow for turning a noisy feature-branch history into a small set of commits, each representing one coherent logical change, before a PR goes up for review. Rather than interactive rebase's fragile pick/squash/reword editor flow, it uses git reset --soft back to the merge-base followed by staged git add + git commit per logical group — simpler, with far fewer merge-conflict surprises. The flow always reads the combined diff first (not just the existing commit messages, which are often wrong or stale) before proposing a regrouping, then presents the planned final shape as a numbered list and waits for explicit approval before touching any history.

It also defines when to offer this proactively: when the user signals a PR is ready ("done with this PR," "let's open it") and the commit log looks like a stream of WIP/fixup commits, suggest the cleanup once — but never insist, and never re-ask in the same session if declined. The guardrails are the load-bearing part: only ever rewrite the current feature branch (refuse on main or an already-merged HEAD), always --force-with-lease on the push, and stop and ask rather than silently re-authoring history if another author's commits are mixed in.


Quick Start

Step 1: Create a Project Folder

mkdir reshape-commits && cd reshape-commits

Step 2: Download the Template

Click Download above, then:

mv ~/Downloads/CLAUDE.md ./

Step 3: Clean Up a Branch

claude

Ask Claude to clean up the commits on your current feature branch before you open (or update) a PR. It will read the base and the full diff, propose a numbered regrouping for your approval, then reset and re-commit — never force-pushing without --force-with-lease and never touching main.


Tips & Best Practices

  • Always let it show the proposed final commit list before executing — a one-line rationale per group makes it easy to catch a wrong split (e.g., a refactor accidentally bundled with a behavior change) before it's baked into history.
  • If your project has a CONTRIBUTING.md with commit-message conventions (type prefixes, scope names, subject rules), point to it — the reshaping should match the house style rather than invent its own.
  • git reset --soft plus staged re-commits is deliberately preferred over interactive rebase here: no editor to drive, no pick/squash lines to get wrong, and conflicts only ever show up once, at the final push.

Limitations

  • Rewrites history — only ever safe on a feature branch that hasn't been merged and that no one else is actively building on top of; the guardrails refuse main and already-merged branches, but a shared feature branch with other active contributors still needs care.
  • Refuses to touch commits authored by someone else without asking first — on a branch with mixed authorship, expect it to stop and check rather than silently reshape everyone's history.
  • Assumes a single target base branch (typically main); a more complex branching model (stacked PRs, multiple integration branches) needs the base identified manually before the flow starts.

$Related Playbooks

Developer Tools

Simplicity First Code Gate

A hard correctness gate against over-complex or oversized code — one ordering principle (human readability first, agent traceability second), five enforceable rules, and a pre-finish checklist that treats unnecessary complexity as a bug, not a style opinion.

2 minutes
Beginner
Developer Tools

Slidev Presentation Builder

Build developer-focused presentations with Slidev — Markdown-driven slides with live code, syntax highlighting, Monaco editor embeds, Mermaid/PlantUML diagrams, LaTeX math, click-based animations, and presenter notes, plus a quick-reference table for the exact syntax each feature needs.

5 minutes
Beginner
Developer Tools

Technical Writing Style Guide

Write docstrings, READMEs, commit messages, and PR descriptions that read like human technical documentation instead of LLM output — six concrete 'tells' with before/after rewrites, a smoothness diagnostic for prose that sounds authoritative while stating one fact three times, and industry-metaphor substitution tables ('surfaces' to 'raises/returns/logs', 'wired through' to 'passed as a parameter').

5 minutes
Intermediate
Developer Tools

Three.js Scroll World Builder

Build a scroll-controlled real-time Three.js experience as one persistent 3D world instead of stacked sections — a scene-ledger data model for authoring chapters, native-scroll-to-deterministic-state mapping with separate exact and smoothed progress, cinematic camera composition, a measurable per-device performance budget, and mandatory reduced-motion and WebGL-failure fallbacks.

20 minutes
Advanced
Developer Tools

Visual Explainer HTML Pages

Have Claude Code explain architectures, diffs and plans as self-contained HTML pages with labeled Mermaid diagrams and a deliberate design pass, instead of walls of chat text, terminal ASCII or generic AI-looking pages.

5 minutes
Intermediate
Developer Tools

Web Animation Design Principles

Design web animations that feel natural and purposeful — a decision-first easing blueprint (ease-out for entrances, ease-in-out for movement, ease for hover), duration and frequency rules, spring configuration, the GPU-only performance rule, and mandatory prefers-reduced-motion accessibility patterns with working CSS and Framer Motion code.

5 minutes
Intermediate
Developer Tools

Web Technique to Skill Extractor

Turn a one-off web visual or interaction technique into a reusable, well-scoped skill — the one-sentence mechanism test that separates a real technique from mere styling, a mechanism-vs-staging sort for what belongs in the skill versus the demo, rules anchored to named failures instead of adjectives, and a demo craft bar that treats the acceptance reference as a target, not inspiration.

10 minutes
Advanced
Developer Tools

Planning with Files

Persistent, file-based planning for multi-step AI-agent work — task_plan.md, findings.md, and progress.md on disk, a 2-action rule for capturing multimodal findings before they're lost, a 3-strike error protocol, and a 5-question reboot test to verify state survives a compaction.

5 minutes
Intermediate
Developer Tools

Secret Scan and Rotation

Find committed credentials in a repository's working tree and full history, triage real secrets from test fixtures, and drive rotation-first remediation — with an absolute rule against ever printing a secret's actual value, even during the scan itself.

5 minutes
Intermediate
Developer Tools

Self-Improvement Loop Design

Design systems where the harness itself is the optimization target — an optimization ladder from prompt to context to workflow to harness code, a two-split empirical acceptance gate, an outside-the-loop invariant for the evaluator, and a catalog of documented reward-hacking and collapse failure modes.

10 minutes
Advanced
Developer Tools

Skill Security Inspector

Review an AI agent skill before installing it using two independent lines — static scanner evidence plus source-aware semantic judgment — checking purpose fit, permission fit, sensitive access, external transmission, execution risk, and persistence, down to a clear APPROVE, CAUTION, or REJECT verdict.

10 minutes
Intermediate
Developer Tools

Writing for AI Agents: A Craft Reference

A theory of writing any document an agent consumes — skills, CLAUDE.md, reference docs — built on context pointers, an information hierarchy of steps versus disclosed reference, completion criteria, and leading words that anchor behavior in the fewest tokens.

10 minutes
Advanced

Browse all Developer Tools playbooks →