SKILL.md
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
``bash git status git branch --show-current ``
- Generate the patch: Create a diff between the base branch and feature branch
``bash git diff <basebranch>...<featurebranch> > /tmp/squash-branch.patch ``
- Switch to base branch and delete feature branch:
``bash git checkout <basebranch> git branch -D <featurebranch> ``
- Recreate feature branch from base and apply patch:
``bash 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:
```bash git add -A git commit -m "<commit_message>
Co-Authored-By: Claude <[email protected]>" ```
- Show final result: Display the new clean commit history
``bash git log --oneline <basebranch>..<featurebranch> git diff --stat <basebranch>...<featurebranch> ``
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 featurebranch=dev/new-feature basebranch=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