Automated summary
Cleans up local branches after a merge by deleting merged branches and updating the base branch.
Strengths
- Auto-detection of base branch and remote
- Protection of sensitive branches (main, develop, release/*, etc.)
- Dry-run mode to preview actions
- Per-repository configuration via git config
Limitations
- Requires Python 3.8+ to run the script
- Does not handle complex merges or non-linear histories
- Remote detection may fail if neither upstream nor origin exist
After merging a feature or hotfix branch to keep your repository clean.
If you want to keep merged branches for reference or are working on multiple branches concurrently.
Security analysis
SafeThe skill only uses git and python to fetch, switch branches, and clean up merged branches. It includes extensive safety checks (protected branches, dirty tree, force flag) and does not expose any destructive or exfiltrating behavior beyond intended local repository management. There are no hidden payloads, network exfiltration, or disabling of safeguards.
No concerns found
How this analysis is madeExamples
/cleanup/cleanup --dry-run/cleanup --force --base developname: cleanup description: Post-merge git branch cleanup with safety checks and auto-detected base branch argument-hint: "[--dry-run] [--force] [--base <branch>] [--remote <name>] [--allow-dirty] [--prune-tags] [--no-update]" disable-model-invocation: true allowed-tools: Bash(git *), Bash(python3 *), Bash(python *)
cleanup
Post-merge branch cleanup: fetch, switch to base branch, fast-forward update, delete merged branch, prune stale refs.
Usage
/cleanup
/cleanup --dry-run
/cleanup --base develop
/cleanup --remote upstream
/cleanup --force
/cleanup --allow-dirty
/cleanup --prune-tags
/cleanup --no-update
Arguments
Access via $ARGUMENTS:
| Flag | Description |
|------|-------------|
| --remote <name> | Remote to operate against (default: auto-detect; prefers upstream over origin) |
| --base <branch> | Base branch to switch to (default: auto-detect via remote HEAD or probe main/master) |
| --force | Force-delete branches not fully merged (git branch -D instead of -d) |
| --allow-dirty | Proceed despite uncommitted changes in the working tree |
| --prune-tags | Also prune local tags not present on the remote |
| --dry-run | Preview what would happen without making changes |
| --no-update | Skip fast-forward update of the base branch |
Per-Repo Configuration
Override defaults per repository using git config:
git config cleanup.base develop # Always use 'develop' as base
git config cleanup.remote upstream # Always use 'upstream' remote
git config --add cleanup.protected-branches 'staging' # Protect extra branches
git config --add cleanup.protected-branches 'release/*' # Protect with glob patterns
Workflow
Context
Current branch:
!git branch --show-current
Remotes:
!git remote -v
Step 1: Run the cleanup script
Locate the script relative to this skill's install location. Try these paths in order:
- Installed path (after
skills-sync):
python3 .claude/skills/cleanup/bin/git-cleanup.py $ARGUMENTS
- Source path (in the toolkit repo):
python3 skills/cleanup/bin/git-cleanup.py $ARGUMENTS
If python3 is not available, use python instead.
Step 2: Report results
Parse the output lines and report the summary to the user:
- Lines prefixed with
[cleanup]are normal operation results - Lines prefixed with
[cleanup:dry-run]show what would happen - Lines prefixed with
[cleanup:warn]are warnings requiring attention - Lines prefixed with
[cleanup:error]indicate failures
Report the [cleanup] output lines verbatim to the user. Do not paraphrase or reformat them.
Safety Semantics
Protected branches are never deleted, even with --force:
- The detected base branch (always)
main,master,develop,staging,production- Branches matching
release/*orhotfix/* - Branches matching patterns in
git config --get-all cleanup.protected-branches
Pattern matching uses fnmatch glob syntax (case-sensitive).
Working tree: Aborts if dirty unless --allow-dirty is passed.
Base update: Uses git merge --ff-only (never creates merge commits). If the base has diverged, exits with error unless --no-update is passed.
Branch deletion: Uses git branch -d (safe delete) by default. If the branch is not fully merged (common with squash merges), suggests --force.
Error Handling
| Exit Code | Meaning | What to tell the user |
|-----------|---------|----------------------|
| 0 | Success (including skipped protected branches) | Report the summary |
| 1 | Fatal error (not a repo, dirty tree, remote/base not found, fetch failed, base diverged) | Report the [cleanup:error] message |
| 2 | Safe-delete refused (branch not fully merged) | Suggest re-running with --force if the PR was merged via squash |
Troubleshooting
Python not found
The script requires Python 3.8+. Verify:
python3 --version
On Windows, try python --version instead.
Remote HEAD not set
If base branch detection fails with "could not detect base branch":
# Set it manually for this repo
git config cleanup.base main
# Or set the remote HEAD
git remote set-head origin --auto
Git version too old
The script uses git switch (Git 2.23+, August 2019). Check your version:
git --version
Branch not fully merged
This typically happens after a squash merge on GitHub/GitLab. The original branch commits are not ancestors of the base, so git branch -d refuses. Use --force to delete with git branch -D after verifying the PR was merged.
From the file to a first result
The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.
View the source and supporting filesThis download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.
1. Download the file
Download SKILL.mdFrom the root of a test project, save the file as .skill-downloads/post-merge-git-branch-cleanup-mmh8qqg4/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.
Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.
mkdir -p '.skill-downloads/post-merge-git-branch-cleanup-mmh8qqg4' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/post-merge-git-branch-cleanup-mmh8qqg4/download' --output '.skill-downloads/post-merge-git-branch-cleanup-mmh8qqg4/SKILL.md.part' && mv '.skill-downloads/post-merge-git-branch-cleanup-mmh8qqg4/SKILL.md.part' '.skill-downloads/post-merge-git-branch-cleanup-mmh8qqg4/SKILL.md'2. Check prerequisites
Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.
Tools declared by the author (check availability in your agent): Bash(git *), Bash(python3 *), Bash(python *)
No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.
The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.
3. Load the skill
After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.
Claude Code
test -f '.skill-downloads/post-merge-git-branch-cleanup-mmh8qqg4/SKILL.md' && test -s '.skill-downloads/post-merge-git-branch-cleanup-mmh8qqg4/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/cleanup' && cp -R '.skill-downloads/post-merge-git-branch-cleanup-mmh8qqg4' '.claude/skills/cleanup'OpenSkills
OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.
Official OpenSkills installationopenskills install './.skill-downloads/post-merge-git-branch-cleanup-mmh8qqg4'openskills read 'post-merge-git-branch-cleanup-mmh8qqg4'Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.
For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.
openskills syncManual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.
4. Try a first task
Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:
Read .skill-downloads/post-merge-git-branch-cleanup-mmh8qqg4/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.
React Hook Form Best Practices
Development
Master React Hook Form: avoid anti-patterns, manage subscriptions, and handle reset, dirty state, and controlled inputs correctly.
Emotion to Mantine Migration
Development
Migrate Emotion styled-components to Mantine components with style props and CSS modules. Use when converting .styled.tsx files or removing @emotion imports.
Scope Creep Detector
Development
Analyzes git diffs against a stated intent to detect scope creep, unrelated files, broad PRs, and oversized changes, then suggests keep, split, or justify actions.