Skip to content

Repo Hygiene Frequently Used Prompts

Noel Saw edited this page Aug 31, 2026 · 2 revisions

Library of frequently used prompts when dealing with lots of local git worktrees & full clone folders -> PRs piled up."

Prompt

Local repo cleanup: open PRs, git worktrees, and full-clone folders.

Respond concisely. Cleanup only — do not start unrelated work or fix unrelated breakage; note it and move on. Measure twice; cut once.

PASS 1 — READ-ONLY INVENTORY (no merges, no deletions, no worktree removal, no branch deletion)

  1. Detect the default branch — in order: git symbolic-ref --short refs/remotes/origin/HEAD (trim the leading origin/); if that fails, gh api repos/{owner}/{repo} --jq .default_branch. If BOTH fail: report "cannot determine default branch" and STOP — never guess main or any other name.
  2. Find every working copy of this repo on this machine: this checkout, every entry in git worktree list, and sibling folders in the SAME parent directory whose basename starts with the repo basename (from basename "$(git rev-parse --show-toplevel)") — do not traverse higher, do not scan the whole disk; if you suspect clones elsewhere, ask me.
  3. For EACH folder report:
    • path, checked-out branch or DETACHED HEAD, and agent session state (active or stopped, best effort)
    • per branch: upstream present? (git rev-parse --abbrev-ref @{u} 2>/dev/null; empty → LOCAL-ONLY, skip ahead/behind for it); ahead/behind ONLY when an upstream exists (git rev-list --left-right --count HEAD...@{u})
    • git status: clean or dirty, with uncommitted, staged, and untracked listed separately; git stash list non-empty = dirty; git submodule status (leading + = diverged, - = uninitialized)
    • in-progress op: any of MERGE_HEAD, REBASE_HEAD, REVERT_HEAD, CHERRY_PICK_HEAD, BISECT_LOG present via git rev-parse --git-path <name> (worktree-safe; do NOT probe <toplevel>/.git/ directly) → mark IN-PROGRESS-OP and EXCLUDE from pass-2 proposals
    • merged? check BOTH git branch --merged <default> AND squash-merges via git cherry <default> <branch> — report which
    • PR state: gh pr list --head <branch> --json number,state,title. If gh is unavailable or errors, write "undetermined" — never guess.
  4. List deletion candidates on origin: branches fully merged with no open PR. Also list untracked scratch files left in any working copy.
  5. Output ONE markdown table with a Disposition column — test conditions in this order and assign the FIRST match: Dirty → Local-only → Unpushed → Pushed-not-merged → Merged (safe to remove) → Unknown / needs review.
  6. Then propose: (a) a safe PR merge sequence with dependency notes, (b) the teardown list, (c) anything that needs my decision. State the expected end state. Then STOP and wait for my explicit approval. Do not delete anything first and apologize later — when in doubt, ask.

PASS 2 — EXECUTE (only what I approved) 7. Merge PRs one at a time in the proposed sequence. Verify checks are green at each step (gh pr view <n> --json statusCheckRollup --jq '.statusCheckRollup[].conclusion'; SUCCESS and NEUTRAL = green, anything else = red). If any target has a red check: STOP, report the failing check(s), and wait for new explicit instruction — never merge with a red check. Resolve only minor conflicts; stop on anything structural. After each merge, run the repo's post-merge housekeeping if it defines one — look in the repo's docs/CONTRIBUTING/README and for conventional scripts (e.g. scripts/post-merge.sh, utils/post-merge.*); if none is defined, skip and say so; if it fails, STOP and report. 8. Delete approved merged branches: local with git branch -d <branch>; origin with git push origin --delete <branch>. Use -d only, never -D, unless I name the branch and say so. If the remote push fails because the branch is already gone, report it as already-deleted and continue — never --force. 9. Tear down approved worktrees with git worktree remove — never rm -rf, never mv. For each approved full-clone folder: cd into it first, then re-verify AT THAT MOMENT: git status --porcelain empty, git stash list empty, and for EVERY branch git log --branches --not --remotes --oneline outputs 0 lines (nothing unpushed anywhere in the folder). If any check fails, skip that folder and report why. 10. Never run: git reset --hard, git checkout -- , tree-wide git stash, git branch -D, rm -rf, or any recursive delete of a path you did not re-verify in step 9. 11. Final verification (if gh was unavailable at PASS 1, re-run gh auth status first; if it still fails, STOP and report "cannot verify PR state without gh"): git fetch origin, then for each surviving folder show branch + clean status (clean = git status --porcelain empty AND git stash list empty AND no in-progress ops) + 0/0 ahead/behind. Confirm every PR is merged/closed or explicitly parked with an issue and a note. End state: one clean primary checkout on the default branch, everything pushed, no leftover worktrees, clone folders, or merged branches. Report any deviation from that state plainly — including what you could not verify.

Clone this wiki locally