xiaohongshu
xiaohongshu
clean-branches
Clean up git branches by analyzing merged/unmerged status, archiving completed work, and organizing active branches. This skill should be used when the user wants to clean up branches, organize their git repository, or review branch status. Triggered by "/clean-branches", "/branches", "clean bran...
Full skill instructions
This skill provides an iterative workflow for cleaning up git branches by analyzing their merge status and organizing them into appropriate namespaces.
ALWAYS run this script first to save tokens:
python .claude/skills/clean-branches/analyze_branches.py
This script:
After reviewing the output, proceed with user approval for any actions (delete, move, archive).
| Namespace | Purpose | Example |
|---|---|---|
archive/completed/<name> | Merged branches (work completed) | archive/completed/feature-login |
archive/stopped/<name> | Unmerged branches (abandoned work) | archive/stopped/experiment-x |
wip/<name> | Work in progress (active development) | wip/new-feature |
| (root) | Keep as-is | feature-y |
Query GitHub to determine the default branch:
gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name'
git fetch --all --prune
Get all local and remote branches:
# Local branches
git branch --list
# Remote branches (excluding HEAD)
git branch -r | grep -v HEAD
For each LOCAL branch (excluding the default branch and already-archived branches):
Check if merged into default branch:
git branch --merged <default-branch> | grep -q <branch-name>
Get last commit info:
git log -1 --format="%h %s (%cr by %an)" <branch-name>
Check if remote exists:
git ls-remote --heads origin <branch-name>
CRITICAL: For local-only branches, check if contained in other branches:
If a branch has no remote, check if its commits are already contained in main or any archived branch:
# Check if branch is ancestor of (contained in) main
git merge-base --is-ancestor <branch> main && echo "Contained in main"
# Check if branch is ancestor of any archived branch
for archived in $(git branch -r | grep "origin/archive/"); do
git merge-base --is-ancestor <branch> $archived 2>/dev/null && echo "Contained in $archived"
done
# Alternative: show all branches that contain this branch's HEAD
git branch -a --contains <branch>
Interpretation:
main → Work was merged, safe to delete local brancharchive/completed/* → Work was completed, safe to delete local brancharchive/stopped/* → Work was archived, safe to delete local branchThis step is often missed! Check remote branches that have NO local copy and are NOT already archived:
# List remote branches not merged into default branch
git branch -r --no-merged main | grep -v HEAD | grep -v "archive/" | grep -v "wip/"
For each remote-only branch found:
Get last commit info:
git log -1 --format="%h %s (%cr by %an)" origin/<branch-name>
Check if contained in default branch or other branches:
# Check what branches contain this remote branch
git branch -a --contains origin/<branch-name>
Check merge status:
# Is it merged into main?
git merge-base --is-ancestor origin/<branch-name> main && echo "Merged into main"
# Is it merged into the current working branch?
git merge-base --is-ancestor origin/<branch-name> HEAD && echo "Merged into HEAD"
Actions for remote-only branches:
main → Move to archive/completed/ (work was merged)# Move remote branch to archive/completed (if merged)
git push origin origin/<branch>:refs/heads/archive/completed/<branch>
git push origin --delete <branch>
# Move remote branch to archive/stopped (if abandoned)
git push origin origin/<branch>:refs/heads/archive/stopped/<branch>
git push origin --delete <branch>
Present a summary table to the user:
| Branch | Status | Last Commit | Age | Remote | Contained In | Recommendation |
|---|---|---|---|---|---|---|
| feature-x | Merged | abc123 Fix bug | 2 weeks | Yes | main | → delete local (work in main) |
| experiment-y | Unmerged | def456 WIP | 3 months | No | archive/stopped/exp-y | → delete local (already archived) |
| new-feature | Unmerged | ghi789 Add X | 1 day | No | (none) | → ask user: WIP/stop/keep |
Key insight: If "Contained In" shows another branch, the work is NOT lost - it's safe to delete the local branch.
For local branches that have no remote but ARE contained in another branch (main or archive/*), the work is already preserved elsewhere. These can be safely deleted:
# Delete local branch that's already contained in main or archive
git branch -d <branch>
Note: Use -d (not -D) which will fail if the branch isn't actually merged/contained - this is a safety check.
For branches that have remotes and are confirmed as merged, offer these options:
Options (in order of preference):
Archive remote + delete local (best option - preserves history on remote):
# Move remote branch to archive
git push origin origin/<branch>:refs/heads/archive/completed/<branch>
# Delete old remote branch
git push origin --delete <branch>
# Delete local branch
git branch -D <branch>
Delete both (when you don't need the branch history):
# Delete remote
git push origin --delete <branch>
# Delete local
git branch -D <branch>
For each unmerged branch, ask the user using AskUserQuestion:
wip/<branch-name>archive/stopped/<branch-name>Then execute the chosen action:
# For WIP
git branch -m <branch> wip/<branch>
git push origin wip/<branch>
git push origin --delete <branch>
# For Stop
git branch -m <branch> archive/stopped/<branch>
git push origin archive/stopped/<branch>
git push origin --delete <branch>
Local archive branches that are synced with remote are redundant - they're safely backed up. Offer to delete them:
Identify synced archive branches:
# Find local archive branches that have matching remote
for branch in $(git branch --list 'archive/*'); do
branch_name=$(echo "$branch" | sed 's/^[* ]*//')
if git ls-remote --heads origin "$branch_name" | grep -q .; then
echo "$branch_name" # Has remote backup, safe to delete locally
fi
done
Present to user:
| Local Archive Branch | Remote Status | Recommendation |
|---|---|---|
| archive/completed/feature-x | ✅ Synced | Delete local (backed up) |
| archive/image-bug | ✅ Synced | Delete local (backed up) |
Offer bulk deletion: Ask using AskUserQuestion:
Execute deletion:
git branch -D <archive-branch> # Safe - remote copy exists
After processing, show updated branch list and ask if further cleanup is needed. Repeat until the user is satisfied.
archive/ or wip/ namespaces (no action needed)Example:
Analysis shows: branch-x is contained in main, safe to delete
[AskUserQuestion]: "Delete local branch `branch-x`? (already in main)"
- Yes, delete
- No, keep
[Only proceed if user selects "Yes"]
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience