Git Hygiene Loop
This loop helps maintain a clean Git repository by identifying and removing stale or outdated branches that are no longer needed. It ensures your branch list remains manageable and reduces clutter in collaborative environments.
Goal
Remove stale branches
How to Run
Run this loop using a prompt-only interface like Cursor, Claude Code, Codex, OpenCode, or Gemini CLI. The agent will iteratively audit branches and remove those considered stale based on configurable guardrails.
- 01
Start the Loop
Initiate the loop by providing the kickoff prompt. The agent will begin auditing your local or remote branches.
- 02
Audit Branches
The agent runs the 'branch audit' command to identify candidate branches for deletion (e.g., merged, old, or inactive).
- 03
Review Results
Inspect the output of the branch audit to confirm which branches are safe to delete under the defined guardrails.
- 04
Delete Stale Branches
If any stale branches are found, the agent will propose or execute their deletion, depending on your environment's capabilities.
- 05
Repeat Until Clean
The loop continues until no more stale branches are detected or the maximum iteration limit is reached.
Workflow Steps
- 01
Run 'git branch --merged' to find branches already merged into the current branch
- 02
Filter out protected and recently active branches based on guardrails
- 03
List remaining branches as potential candidates for deletion
- 04
Delete each candidate branch after user confirmation or automatic approval
- 05
Re-run audit to verify cleanup progress and exit when no stale branches remain
Kickoff Prompt
Start the "Git Hygiene Loop" loop. Goal: Remove stale branches Max iterations: 10 Between iterations run: branch audit Exit when: Cleanup complete Please start the Git Hygiene Loop. Audit all local and remote branches, identify stale ones that have been merged and are older than 30 days, and remove them following the guardrails. Repeat this process up to 10 times or until no more stale branches are found. Self-pace this loop. After each iteration, run `branch audit` and evaluate the output, and only continue if the exit condition is not met (Cleanup complete). Stop when the exit condition passes or 10 iterations are reached. Give a short status update each pass.
Guardrails
hardcoded- ·Do not delete the currently checked-out branch
- ·Avoid deleting protected branches (e.g., main, master, develop) unless explicitly allowed
- ·Preserve branches with commits made within the last X days (configurable)
- ·Skip branches that are actively tracked by CI/CD pipelines or other automation tools
- ·Prompt user before deleting any branch if unsure about its status
Flow Diagram
Related loops — Git
Git
Conventional Commit Enforcer
This loop ensures all Git commits follow the Conventional Commits specification by using commitlint to validate commit messages. It automatically detects non-compliant commits, suggests fixes, and guides the user through correcting them until all commits pass validation.
Git
Large Commit Splitter
Automatically splits large, monolithic Git commits into smaller, more reviewable units while preserving logical code boundaries and maintaining clean history.
Git
Merge Conflict Resolver
Automate the resolution of Git merge conflicts by iteratively detecting conflicts, resolving them, and retrying the merge until successful.