Branches Clean (Gait)
Execute this workflow when asked to clean up branches by deleting all non-main branches locally and on a configured remote (default origin).
Scope
- Repository:
/Users/tr/gait - Target: all non-
mainbranches - Deletion style: one-by-one only (no grouped delete commands)
- Applies to:
- local branches
- remote
<remote>/*branches (defaultorigin)
Input Contract
mode:executeonlyforce_local_delete: alwaystruefor this skill- Optional:
remote: defaults toorigin
Safety Rules
- Never delete
main. - Always switch to
mainbefore deletion. - Always sync main before deletion:
git fetch <remote> maingit checkout maingit pull --ff-only <remote> main- No grouped branch deletion commands.
- Delete branches one-by-one only.
Command Anchors (JSON Required)
- Capture machine-readable diagnostics before destructive actions:
gait doctor --jsongait gate eval --policy examples/policy/base_low_risk.yaml --intent examples/policy/intents/intent_read.json --json
Workflow
- Preflight:
- confirm repo is valid git repo
- resolve current branch
- verify
<remote>/mainexists - switch to
mainand sync fast-forward - fetch/prune remote refs (
git fetch --prune <remote>)
- Build delete candidates:
- Local candidates: all local branches except
main - Remote candidates: all
<remote>/<branch>except<remote>/main - Exclude symbolic refs (
<remote>/HEAD) and<remote>root alias (<remote>) if present.
- Execute deletion (always):
- Local deletion one-by-one:
git branch -D <branch>- Remote deletion one-by-one:
git push <remote> --delete <branch>- Never run
git push <remote> --delete <remote>;<remote>is not a branch. - if already deleted/not found, record as skipped and continue
- Final reconciliation:
git fetch --prune <remote>- list remaining local branches
- list remaining
<remote>/*branches
- Output summary:
- deleted local branches
- deleted remote branches
- skipped/failed branches with reasons
- final remaining branch lists
Command Discipline
Use one-by-one commands only, such as:
git branch -D <name>git push <remote> --delete <name>
Do not use batched deletion forms.
Shell Portability
- Do not rely on
mapfile. - Build branch candidate lists with portable
while IFS= read -rloops. - Ensure commands work under default macOS shell environments (
zsh, olderbash).
Failure Handling
- Continue on per-branch failures; do not abort whole run.
- Record each failure with command + stderr reason.
- If remote delete returns
remote ref does not exist, record asskippedand continue. - If
<remote>/mainis missing, or if cannot switch/syncmain, stop immediately.
Expected Output
Mode: executeLocal candidates: list + countRemote candidates: list + countDeleted local: listDeleted remote: listSkipped/failed: list with reasonsRemaining local: listRemaining remote: list
Converted and distributed by TomeVault — claim your Tome and manage your conversions.