Git (clean)
Clean up merged branches locally and on remote, keeping only main, dev, and gh-pages.
Front matter
description: Clean up merged branches locally and on remote, keeping only main, dev, and gh-pages.Clean up stale branches that have been merged or are no longer needed.
Steps
- List local branches to delete (excluding
main,dev,gh-pages):
git branch | grep -v -E '^\*|main$|dev$|gh-pages$'Report what will be deleted. If no branches found, say "No local branches to clean" and skip to step 3.
- Delete local branches that are fully merged:
git branch -d <branch-name>If a branch is not fully merged, report it to the user and ask whether to force-delete. Do NOT force-delete without confirmation.
- List remote branches to delete (excluding
main,dev,gh-pages,HEAD):
git branch -r | grep -v -E 'origin/main$|origin/dev$|origin/gh-pages$|origin/HEAD'Report what will be deleted. If no branches found, say "No remote branches to clean" and skip to step 5.
- Confirm with the user before deleting remote branches. Show the full list and wait for approval. Then delete:
git push origin --delete <branch-names>- Prune stale remote refs:
git remote prune origin- Report final state:
git branch # local
git branch -r # remotePresent a summary:
| Item | Count |
|---|---|
| Local branches deleted | N |
| Remote branches deleted | N |
| Remaining local | main, dev |
| Remaining remote | origin/main, origin/dev, origin/gh-pages |
Source: https://github.com/alirezarezvani/claude-skills/blob/main/.claude/commands/git/clean.md
Author: alirezarezvani, Alireza Rezvani skills and agents. License: MIT.
Shown here with formatting for the web. Keep the author and license notice when you reuse it.
Related entries
There are more like this in the members library
The Codex library holds 7,009 entries. Members can search all of them by meaning and read every one in full.