Gitprompt onlyMedium

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.

← all loops
gitcleanupbranchesrepository hygieneautomation

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.

  1. 01

    Start the Loop

    Initiate the loop by providing the kickoff prompt. The agent will begin auditing your local or remote branches.

  2. 02

    Audit Branches

    The agent runs the 'branch audit' command to identify candidate branches for deletion (e.g., merged, old, or inactive).

  3. 03

    Review Results

    Inspect the output of the branch audit to confirm which branches are safe to delete under the defined guardrails.

  4. 04

    Delete Stale Branches

    If any stale branches are found, the agent will propose or execute their deletion, depending on your environment's capabilities.

  5. 05

    Repeat Until Clean

    The loop continues until no more stale branches are detected or the maximum iteration limit is reached.

Workflow Steps

  1. 01

    Run 'git branch --merged' to find branches already merged into the current branch

  2. 02

    Filter out protected and recently active branches based on guardrails

  3. 03

    List remaining branches as potential candidates for deletion

  4. 04

    Delete each candidate branch after user confirmation or automatic approval

  5. 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

rendering…

Related loops — Git