squash-branch
Cleans up commit history by squashing multiple feature branch commits into a single commit.
Install
mkdir -p .claude/skills/squash-branch && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/11710" && unzip -o skill.zip -d .claude/skills/squash-branch && rm skill.zipInstalls to .claude/skills/squash-branch
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Squash all commits on a feature branch into a single commit. Use when the user wants to clean up commit history, squash commits, or consolidate branch changes into one commit.Key capabilities
- →Generate a patch from a feature branch against a base branch
- →Reset the feature branch to the base branch
- →Apply the generated patch as a single commit
- →Prompt for a commit message if not provided
- →Display the new clean commit history and diff statistics
How it works
The skill generates a diff patch from the feature branch, switches to the base branch, deletes and recreates the feature branch from the base, then applies the patch as a single commit.
Inputs & outputs
When to use squash-branch
- →Clean up feature branch history
- →Consolidate commit logs
- →Prepare clean PRs
About this skill
Squash Branch Skill
Squash all commits on a feature branch into a single commit by generating a patch, recreating the branch from the base, and applying the patch.
Parameters
The user should provide:
- feature_branch: The branch to squash (e.g.,
jose/vectors,feature/my-feature) - base_branch: The branch to squash against (e.g.,
mainline,main,master) - commit_message (optional): If not provided, prompt the user for a commit message
Instructions
-
Verify current state: Ensure the working directory is clean and you're on the feature branch
git status git branch --show-current -
Generate the patch: Create a diff between the base branch and feature branch
git diff <base_branch>...<feature_branch> > /tmp/squash-branch.patch -
Switch to base branch and delete feature branch:
git checkout <base_branch> git branch -D <feature_branch> -
Recreate feature branch from base and apply patch:
git checkout -b <feature_branch> git apply /tmp/squash-branch.patch -
Prompt for commit message: If no commit message was provided, use AskUserQuestion to ask the user what commit message they want
-
Stage and commit:
git add -A git commit -m "<commit_message> Co-Authored-By: Claude <[email protected]>" -
Show final result: Display the new clean commit history
git log --oneline <base_branch>..<feature_branch> git diff --stat <base_branch>...<feature_branch>
Example Usage
User: "Squash my feature/auth branch against main with message 'Add user authentication'"
User: "Clean up the commit history of jose/vectors against mainline"
User: "/squash-branch feature_branch=dev/new-feature base_branch=main"
Important Notes
- This operation is destructive to the local branch history - make sure changes are not pushed and nothing other than the feature branch is modified
- Always verify the patch was created successfully before deleting the branch
- If the patch application fails, the original branch is already deleted - warn the user about this risk
- The patch file is stored in /tmp and will be cleaned up by the system
When not to use it
- →When the working directory is not clean
- →When the local branch history should not be destructively modified
- →When changes other than the feature branch are modified
Limitations
- →This operation is destructive to the local branch history
- →The original branch is deleted if the patch application fails
- →The patch file is stored in `/tmp` and will be cleaned up by the system
How it compares
This skill consolidates all commits on a feature branch into a single commit by generating and applying a patch, providing a cleaner history than interactive rebase.
Compared to similar skills
squash-branch side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| squash-branch (this skill) | 0 | 5mo | Review | Intermediate |
| ast-grep-find | 3 | 7mo | Review | Intermediate |
| clean | 4 | 3mo | Review | Intermediate |
| code-transfer | 1 | 9mo | Review | Beginner |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by diegosouzapw
View all by diegosouzapw →You might also like
ast-grep-find
parcadei
AST-based code search and refactoring via ast-grep MCP
clean
catlog22
Intelligent code cleanup with mainline detection, stale artifact discovery, and safe execution. Supports targeted cleanup and confirmation.
code-transfer
mhattingpete
Transfer code between files with line-based precision. Use when users request copying code from one location to another, moving functions or classes between files, extracting code blocks, or inserting code at specific line numbers.
framework-migration-code-migrate
sickn33
You are a code migration expert specializing in transitioning codebases between frameworks, languages, versions, and platforms. Generate comprehensive migration plans, automated migration scripts, and
tdd-migrate
parcadei
TDD workflow for migrations - orchestrate agents, zero main context growth
windsurf-multi-file-editing
jeremylongshore
Manage multi-file edits with Cascade coordination. Activate when users mention "multi-file edit", "edit multiple files", "cross-file changes", "refactor across files", or "batch modifications". Handles coordinated multi-file operations. Use when working with windsurf multi file editing functionality. Trigger with phrases like "windsurf multi file editing", "windsurf editing", "windsurf".