Clean branches

From Goldziher/ai-rulez · View interactive version

Clean branches is an AI agent skill from the GitHub repository Goldziher/ai-rulez. Clean up unnecessary local branches and prune stale remote-tracking branches

How to use this skill

Skill file

Clean Branches

Clean up unnecessary local branches and prune stale remote-tracking branches.

Step 1: Inspect Current State

Run the following:

Identify:

After identifying the default branch, list branches already merged into it:

If you want to use the remote-tracking branch as the source of truth, use:

Step 2: Refresh Remote State

Update remote refs and prune deleted remote branches:

git fetch --prune

If needed, also run:

git remote prune origin

Step 3: Select Branches to Delete

Delete only branches that are clearly unnecessary.

Safe candidates include:

Never delete:

If there is any ambiguity, show the candidate branches to the user and ask for confirmation.

Step 4: Delete Branches

For merged branches, delete them safely:

git branch -d <branch-name>

Only if the user explicitly approves force deletion for unmerged branches, use:

git branch -D <branch-name>

Delete branches one by one, not with a broad wildcard command.

Step 5: Report Result

Summarize:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.