[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M73502CC9CK7CT21EDC48753":3,"skill-same:01M73502CC9CK7CT21EDC48753":51},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":30,"commitSha":31,"skillDirectory":32,"forksCount":33,"repositoryHtmlUrl":34,"repositoryHomepageUrl":35,"ownerHtmlUrl":36,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":37,"install":38,"resources":50},"01M73502CC9CK7CT21EDC48753","clean-branches",null,"Clean dead or stale Git branches.","Morrison-Lab\u002Fai-config","Morrison-Lab","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F104235520?v=4","01M734G0451S2G35MN4HFQK7XP","Morrison Lab","01M734G059BYFDFQA8YTPDGPMH",4,"MIT","https:\u002F\u002Fgithub.com\u002FMorrison-Lab\u002Fai-config\u002Fblob\u002Fmain\u002Fskills\u002Fclean-branches\u002FSKILL.md",[],[],"2026-11-11 15:11:14",false,"---\nname: clean-branches\ndescription: \"Clean dead or stale Git branches.\"\nuser-invocable: true\nallowed-tools:\n  - Bash\n  - Read\n  - Edit\n  - Write\n---\n\n# Clean Branches (aka CB \u002F prune)\n\nAudit branches in the current repo — **both your local checkout and the\nremote**. Delete dead ones, rebase stale ones, open MRs for orphaned work, and\nsweep up local-only stragglers — all without disrupting active sessions.\n\n## When this fires\n\n- User says \"clean branches\", \"cb\", \"prune\", \"prune branches\", \"tidy up branches\"\n- User says \"clear dead branches\", \"clean up the repo\"\n- User says \"what branches can we delete?\"\n\n## Scope: local AND remote\n\nPrune in both places — they accumulate junk independently:\n\n- **Remote** branches — dead\u002Fstale\u002Forphaned remote refs (the bulk of this skill).\n- **Local** branches — branches that linger in your checkout after their PR\n  merged, or whose upstream remote was deleted (`[gone]`). The remote pass\n  alone won't catch a local branch whose remote is already gone, so there's a\n  dedicated local pass (step 8).\n\n## Definitions\n\n| Category | Criteria | Action |\n|----------|----------|--------|\n| **Dead** | Purely behind main (no unique commits ahead), no open MR, no linked issue, not created in the last 7 days | Delete |\n| **Stale** | Has unique commits ahead of main but is behind main, no recent activity (>30 days), not actively being worked on | Rebase on main, open MR if none exists |\n| **Active** | Has an open MR, linked issue, recent commits (\u003C30 days), or a claim comment | Skip — don't touch |\n| **New** | Created in the last 7 days | Skip — too fresh to judge |\n| **Local merged** | *Local* branch fully merged into main, or whose PR merged (upstream `[gone]`) | Delete locally (`git branch -d`) — step 8 |\n| **Local-only unpushed** | *Local* branch with unique commits, never pushed, no MR | Flag — ask before touching (step 8) |\n\nThe first four rows apply to **remote** branches (steps 1–7); the last two are\nthe **local** pass (step 8). A branch can need both — e.g. delete the remote ref\n*and* the leftover local tracking branch.\n\n## Procedure\n\n### 1. Detect the forge\n\n```bash\ngit remote get-url origin\n```\n\nDetermine GitHub (`gh`) vs GitLab (`glab`).\n\n### 2. Fetch and list remote branches\n\n```bash\ngit fetch --prune origin\ngit branch -r --merged origin\u002Fmain | grep -v 'origin\u002Fmain\\|origin\u002FHEAD'\ngit branch -r --no-merged origin\u002Fmain\n```\n\n**First separate real remote branches from stray ref namespaces, or the\nsweep's scope is wrong from its first command.**\nA one-off `git fetch origin '+refs\u002Fpull\u002F*\u002Fhead:refs\u002Fremotes\u002Fpr\u002F*'` writes refs\nthat no configured refspec matches, so nothing updates them and `--prune`\nnever touches them --- but `git branch -r` counts them anyway.\n\n```bash\ngit config --get-all remote.origin.fetch                                  # what is tracked\ngit for-each-ref --format='%(refname)' | grep -v '^refs\u002Fremotes\u002Forigin\u002F'  # what is not\n```\n\nAnything outside the tracked namespace is local cruft rather than a branch:\n`git push origin --delete` cannot touch it, and it belongs in a separate\n`git update-ref --stdin` sweep, not in the plan below.\n\n**Write ref patterns with `**`, because a single `*` does not cross a slash.**\n`git for-each-ref 'refs\u002Fremotes\u002Forigin\u002F*'` silently omits every slash-named\nbranch --- `feat\u002F`, `fix\u002F`, `claude\u002F` --- which is every branch anyone named\nconventionally, including the ones carrying open PRs.\nNothing errors; the count merely comes back smaller and entirely plausible.\nNote this is the **opposite** of pathspec matching, where `*` does cross a\nslash; see `memories\u002Fgit-diffing.md`, \"A ref pattern is not a pathspec\".\n\n```bash\ngit for-each-ref --format='%(refname:short)' 'refs\u002Fremotes\u002Forigin\u002F**'\n```\n\nGive the enumeration a control before trusting a total: confirm a known\nslash-named branch appears in the output.\nA shortfall here is indistinguishable from a tidy repo.\n\n### 3. Classify each branch\n\nFor each remote branch (excluding `main`, `HEAD`, protected branches):\n\n#### a. Check if it's purely behind main (merged\u002Fdead)\n\n```bash\n# Commits on branch not on main (ahead count)\ngit rev-list --count origin\u002Fmain..origin\u002F\u003Cbranch>\n\n# If 0 → branch is purely behind main (already merged or never diverged)\n```\n\n#### b. Check recency\n\n```bash\ngit log -1 --format='%ci' origin\u002F\u003Cbranch>\n```\n\nSkip if created\u002Flast-committed within the last 7 days (too new).\n\n#### c. Check for open MR\u002FPR\n\n```bash\n# GitLab\nglab mr list --source-branch=\u003Cbranch> 2>&1 | cat\n\n# GitHub\ngh pr list --head=\u003Cbranch> --json number,title,state | cat   # LIST_PRS\n```\n\nIf an open MR exists → **Active**, skip.\n\n**Fetch every PR once and match locally, rather than querying per branch.**\nA sweep of N branches costs N API round-trips this way, which is slow and\nrate-limit-prone at repo scale; one call answers for all of them, and it also\nsupplies the *merged* and *closed-unmerged* states that b and f need.\n\n```bash\ngh pr list --state all --limit 2000 \\\n  --json number,headRefName,state,mergedAt,url,title > \u002Ftmp\u002Fall-prs.json   # LIST_PRS\n```\n\nThen index by `headRefName` and look each branch up in memory.\nRaise `--limit` above the repo's total PR count and check the returned length\nagainst it --- a silently truncated list marks live branches as having no PR,\nwhich is the one error in this sweep that deletes something.\n\n#### d. Check for linked issues\n\nLook for branch naming patterns that reference issues:\n- `fix\u002F123-*`, `feat\u002F123-*`, `issue-123-*` → check if issue #123 is open\n- If the linked issue is open → **Active**, skip\n\n#### e. Check for active work claims\n\n```bash\ngh pr view \u003CN> --json comments \\\n  -q '.comments[] | select(.body | test(\"hold off|paws off|back off\"; \"i\"))\n      | select((.body | test(\"unclaim|released|PR is free|now mergeable\"; \"i\")) | not)\n      | \"\\(.author.login): \\(.body)\"'   # READ_PR_COMMENTS\n```\n\nIf a claim comment exists within the last 24 hours → **Active**, skip.\nThis window is deliberately wider than\n[`claim-pr`](..\u002F..\u002Fshared\u002Fworkflow\u002Fclaim-pr.md)'s 2-hour claim expiration:\nthat rule decides who may *start work*, where the cost of over-respecting a\ndead claim is a wait; this check gates branch *deletion*, which is\ndestructive, so it errs further toward keeping.\n\n#### f. If the PR closed unmerged, diff the branch against main before believing it\n\nCheck c only asks whether an **open** PR exists, so a branch whose PR closed\nunmerged falls straight through to a delete classification.\nThat is right for an abandoned branch and wrong for a superseded one, because a\nclosure rationale describes the PR's **stated purpose**, not an inventory of its\ndiff.\n\"Superseded by #260, all review findings addressed\" is a claim about the\nfeature; it says nothing about an unrelated fix that happened to share the\nbranch.\n\nThe gap is easy to miss in exactly the case that matters, since the rationale is\nusually accurate about the thing it names, and the leftover work is by\ndefinition the part nobody was talking about.\nNothing else flags it either: `git branch -d` consults the upstream rather than\n`main` (see the safety rules below), the superseding PR merged and closed the\nissue, and the tracker looks clean.\n\nSo for any branch whose PR closed **unmerged**, compare the files rather than\nreading the closure comment:\n\n```bash\ngh pr list --head \u003Cbranch> --state closed \\\n  --json number,title,mergedAt,url | cat                     # LIST_PRS\ngh pr diff \u003CN> --name-only                                   # DIFF_PR\ngit diff --stat origin\u002Fmain...origin\u002F\u003Cbranch>                # what is still unlanded\n```\n\n`mergedAt: null` on a closed PR is the trigger.\nThen diff each file the branch touched against `main`;\nanything still absent is unlanded work, and the branch is **Stale**, not Dead\n--- rebase it and open an MR (steps 6--7), or file an issue for the salvageable\npart and say so in the plan before deleting.\n\nWeight the check by how far the branch's contents stray from its title: a branch\ncarrying commits unrelated to the PR that named it is the shape this catches.\n`rescue-closed` is the deliberate, whole-tracker version of the same sweep; this\nis the minimum owed before a deletion.\n\n(2026-07-29: a bcs branch closed as superseded still carried an orthogonal\nout-of-memory fix --- `geepack::geeglm` replaced by `glm` + `sandwich::vcovCL`\n--- that the superseding privacy redesign never touched.\nDeleting on the closure rationale would have discarded it silently;\nfiled instead as `ucdavis\u002Fbcs#466`.)\n\n**Once you have found unlanded work, the deliverable is a tracking issue --- not\nkeeping the branch.**\nOn GitHub the branch is not the only copy: `refs\u002Fpull\u002FN\u002Fhead` is retained\npermanently and still resolves after the head branch is deleted.\nSo the choice is not \"delete or preserve\", it is \"record or lose track of\",\nwhich is a much easier call and lets the sweep finish.\n\nVerify rather than assume, since it is one call per PR, then put the recovery\ncommand in the issue:\n\n```bash\ngit ls-remote origin 'refs\u002Fpull\u002F\u003CN>\u002Fhead'    # should equal the branch tip\ngit fetch origin refs\u002Fpull\u002F\u003CN>\u002Fhead\ngit checkout -b recover\u002F\u003CN> FETCH_HEAD\n```\n\nAn issue naming what was unlanded, how much of it, and that command is strictly\nmore useful than a stale branch nobody will revisit --- and unlike the branch,\nit appears in the tracker.\n(2026-08-02, `Morrison-Lab\u002Fai-config`: six closed-unmerged branches carried\nwork absent from `main`; every `refs\u002Fpull\u002FN\u002Fhead` resolved and matched its\nbranch tip exactly, so all six were deleted after the two substantial ones were\nfiled as #1062 and #1063.)\n\n### 4. Present the plan (dry run)\n\nBefore taking any action, present a table to the user:\n\n```\n## Branch Cleanup Plan\n\n| Branch | Last commit | Status | Action |\n|--------|-------------|--------|--------|\n| `old-feature` | 2025-03-15 | Dead (merged) | 🗑️ Delete |\n| `wip-refactor` | 2025-11-20 | Stale (45 days, no MR) | 🔄 Rebase + open MR |\n| `fix\u002F42-typo` | 2026-06-15 | Active (open MR !80) | ⏭️ Skip |\n| `experiment` | 2026-06-12 | New (\u003C7 days) | ⏭️ Skip |\n\nProceed? (or pick specific branches to act on)\n```\n\nWait for user confirmation before proceeding. If user says \"just go\" or\n\"do it\", proceed with all proposed actions.\n\n### 5. Delete dead branches\n\n```bash\ngit push origin --delete \u003Cbranch>   # DELETE_REF\n```\n\nAlso clean up local tracking branches:\n```bash\ngit branch -d \u003Clocal-tracking-branch>  # if it exists locally\n```\n\n### 6. Rebase stale branches\n\nFor each stale branch:\n\n```bash\ngit checkout -B \u003Cbranch> origin\u002F\u003Cbranch>   # -B (not -b) force-resets if the branch already exists locally\ngit rebase origin\u002Fmain\n```\n\nIf rebase has conflicts:\n- Attempt to resolve automatically (see the `resolve-conflicts` skill —\n  consolidate both sides, don't blind-pick)\n- If conflicts are non-trivial, skip this branch and report it\n- Don't force-push a broken rebase\n\nIf rebase succeeds:\n```bash\ngit push --force-with-lease origin \u003Cbranch>   # PUSH\n```\n\n### 7. Open MRs for orphaned stale branches\n\nFor stale branches that have no open MR after rebasing:\n\n```bash\n# GitLab — assign to the current glab user (override ASSIGNEE to assign someone else)\nASSIGNEE=\"$(glab api user 2>\u002Fdev\u002Fnull | python3 -c \"import json,sys; print(json.load(sys.stdin)['username'])\")\"\nglab mr create --source-branch=\u003Cbranch> --target-branch=main \\\n  --title \"\u003Cinferred title from branch name>\" \\\n  --description \"Orphaned branch rebased onto main. Review or close if no longer needed.\" \\\n  ${ASSIGNEE:+--assignee \"$ASSIGNEE\"}\n\n# GitHub\ngh pr create --head=\u003Cbranch> --base=main \\\n  --title \"\u003Cinferred title>\" \\\n  --body \"Orphaned branch rebased onto main. Review or close if no longer needed.\"   # CREATE_PR\n```\n\n### 8. Prune local branches\n\nThe remote pass doesn't touch branches that only exist in your checkout. Sweep\nthose too. First refresh remote-tracking state so \"merged\" and \"gone\" are\naccurate:\n\n```bash\ngit fetch --prune origin                       # marks deleted upstreams as [gone]\ngit branch --show-current                      # never delete the branch you're on\n```\n\n**The `--prune` is a prerequisite, not a refresh --- without it step b finds\nnothing and reports success.** `[gone]` is produced *by* pruning, not by the\nbranch being deleted upstream: until a prune runs, `%(upstream:track)` is\nempty for exactly the branches b exists to find, so its `grep` matches zero\nrows and the sweep says there is nothing to clean.\nThe \"nothing found\" and \"never ran\" paths print the same thing,\nso never take a zero-row result as clean\nunless this fetch actually ran in this sweep.\n\nRecommend the standing setting once, since it makes every other tool's view\ncorrect too --- but keep the explicit `--prune` above regardless, so the sweep\ndoes not depend on the user's config:\n\n```bash\ngit config --global fetch.prune true          # or per-remote:\ngit config --global remote.origin.prune true\n```\n\nThat setting only prunes `refs\u002Fremotes\u002Forigin\u002F*`.\nIt never deletes a local branch, so it replaces none of the steps below.\n\nClassify each **local** branch (excluding `main`\u002F`master`\u002Fprotected and the\ncurrent branch):\n\n#### a. Merged into main → delete\n\n```bash\n# Branches checked out in ANY worktree cannot be deleted, and the --format\n# listing below carries no marker for them, so derive that set read-only\n# first. A per-run temp file, not a fixed \u002Ftmp name: two sessions sweeping\n# at once would otherwise read each other's set.\nCHECKED_OUT=$(mktemp); MERGED=$(mktemp); CURRENT=$(git branch --show-current)\ngit worktree list --porcelain \\\n  | awk '\u002F^branch \u002F{sub(\"refs\u002Fheads\u002F\", \"\", $2); print $2}' | sort -u > \"$CHECKED_OUT\"\n\n# The unfiltered merged list, so the two rows below can both be derived.\ngit branch --merged origin\u002Fmain --format='%(refname:short)' \\\n  | grep -vxF -e main -e master -e \"$CURRENT\" > \"$MERGED\"\n# --format gives plain names. Plain `git branch` prefixes the current branch\n# with `*` and a branch checked out in a linked worktree with `+`, so a\n# column-anchored grep on the plain listing mangled such a name into\n# `+ feature\u002Ffoo` and the delete below failed on it (ai-config#1882; the\n# clean-worktrees skill's step 3c records the same hazard). With no `*` to\n# filter, the current branch is excluded by name, per this step's contract.\n# `grep -vxF` matches whole lines literally, so a branch like\n# `maintain-docs` or `feature-main-menu` is NOT silently filtered out.\n\n# Merged but held by a linked worktree: skipped, and listed as such.\ngrep -xF -f \"$CHECKED_OUT\" \"$MERGED\"\n# Merged and free: delete candidates.\ngrep -vxF -f \"$CHECKED_OUT\" \"$MERGED\"\n# Compare against origin\u002Fmain (just fetched), NOT local `main` — your local main\n# may be behind, which would hide branches that are actually merged.\ngit branch -d \u003Cbranch>          # -d refuses if NOT actually merged — a safety net\n```\n\nA merged branch in the first list gets the status `checked out in a\nworktree` in the local plan (the step 4 table when the local rows are\nfolded into a full sweep, or the standalone local plan step 8c describes)\nand goes under \"Skipped (checked out in a worktree)\" in the step 9 report.\nClearing it is the worktree's business, not this skill's: switch that\ncheckout to another branch, or run `clean-worktrees` when the worktree is\none it would retire (it never removes the main or current worktree, and it\nskips active or fresh ones).\n`-d` (never `-D`) is deliberate: `error: the branch 'X' is not fully merged`\nmeans unmerged commits, so treat the branch as **stale**, not dead (see b).\n`error: cannot delete branch 'X' used by worktree at ...` means the\nchecked-out set went stale since it was derived; re-derive it rather than\nretrying.\n\n#### b. Upstream gone but the PR merged → delete\n\nA branch whose remote was deleted shows `[gone]`:\n\n```bash\ngit for-each-ref --format='%(refname:short) %(upstream:track)' refs\u002Fheads \\\n  | grep '\\[gone\\]'\n```\n\nFor each, confirm the PR\u002FMR actually merged before deleting (never assume):\n\n```bash\n# GitHub\ngh pr list --head \u003Cbranch> --state merged --json number,mergedAt | cat   # LIST_PRS\n\n# GitLab\nglab mr list --source-branch=\u003Cbranch> --state merged 2>&1 | cat\n```\n\n- PR merged → `git branch -D \u003Cbranch>` is acceptable here (the work landed via\n  squash\u002Frebase merge, so `-d` may not see it as merged). Confirm the merge\n  first.\n- No merged PR and unique commits exist → **stale local work**: don't delete;\n  offer to push it and open an MR (step 7 mechanics).\n\n**Read the PR, not local ancestry, to decide whether the work landed.** In a\nrepo that squash-merges --- `ucdavis\u002Fbcs` and `Morrison-Lab\u002Fai-config` both do\n--- a branch whose work is already on `main` still reports a non-zero\nahead-count, is not an ancestor of `main`, is absent from\n`git branch --merged`, and is refused by `git branch -d`.\nAll four say \"unmerged\" about a branch that merged,\nbecause the squash commit is a different commit.\nSo treat a `-d` refusal as *unproven*,\nnever as evidence the branch holds unique local work ---\nthat is what the merged-PR lookup above is for,\nand why `-D` is the right tool once it comes back positive.\n\nThe converse still holds and is what keeps this safe: no merged PR **and**\nunique commits means the work may exist nowhere else,\nso it is never deleted without confirmation.\nWhen the PR lookup is inconclusive,\ncheck content rather than ancestry, since content survives a squash:\n\n```bash\ngit show origin\u002Fmain:\u003Cpath> | grep \u003Csomething-the-branch-added>   # did it land?\n```\n\n#### c. Never pushed, has unique commits → keep, but flag\n\n```bash\ngit for-each-ref --format='%(refname:short) %(upstream)' refs\u002Fheads \\\n  | awk '$2==\"\" {print $1}'      # local branches with no upstream at all\n```\n\nReport these as \"local-only, unpushed\" and ask before doing anything — they may\nbe in-progress work that hasn't been pushed yet. Don't delete without\nconfirmation.\n\nApply the same dry-run discipline to local deletions as step 4 does for remote\nbranches — **no silent local deletions**. If you're doing a full local+remote\nsweep, fold these local rows into the step-4 plan and present them together; if\nyou're running the local pass on its own, present a standalone local plan here\nand wait for confirmation before deleting anything.\n\nA standing [`daytb`](..\u002Fdaytb\u002FSKILL.md) grant lifts this confirm step for the safe cases --- deleting a merged local branch is one of the local-git housekeeping actions that grant explicitly covers.\nThe skill's own safety preconditions are unchanged, and anything carrying commits reachable from no remote still asks.\n\n### 9. Report\n\nPrint a summary covering **both** local and remote:\n\n```\n## Branch Cleanup Complete — \u003Ctimestamp>\n\n### Deleted — remote (dead)\n- `old-feature` (last commit 2025-03-15, merged into main)\n\n### Deleted — local (merged \u002F upstream gone)\n- `add-wrap-up-skill` (PR #26 merged; local straggler)\n- `ums-session-learnings` (merged into main)\n\n### Rebased + MR opened (stale)\n- `wip-refactor` → [!85](url) (rebased, 3 commits ahead)\n\n### Skipped (active\u002Fnew)\n- `fix\u002F42-typo` — open MR !80\n- `experiment` — created 2 days ago\n\n### Skipped (checked out in a worktree)\n- `feature\u002Ffoo` (merged, but checked out at `..\u002Fwt-foo`): run `clean-worktrees` first\n\n### Flagged — local-only, unpushed (left alone)\n- `scratch-idea` — 4 unpushed commits, no MR; your call\n\n### Failed (conflicts)\n- `ancient-branch` — rebase conflicts, needs manual resolution\n```\n\n## Safety rules\n\n- **A merged PR settles that the work landed --- stop measuring there.**\n  The content checks above exist for branches whose fate is *unknown*.\n  Once `gh pr list --state merged` names a PR for the branch, residual\n  differences against `main` are the branch's pre-review draft versus the\n  post-review text that actually merged, and mean nothing about safety.\n  Measuring anyway invents doubt about the one case that is already certain:\n  in a 2026-08-02 sweep, 47 of 50 local branches had merged PRs and several\n  scored under 90% on a line-presence check purely because review had reworded\n  them.\n- **A GitHub branch is never the only copy of a PR's work.**\n  `refs\u002Fpull\u002FN\u002Fhead` is retained permanently and resolves after the head\n  branch is deleted, so \"delete the branch\" and \"lose the work\" are different\n  events on GitHub.\n  This does not weaken the local-only rule below --- a branch that was **never\n  pushed** has no PR ref behind it, and that is exactly the case that needs\n  confirmation.\n- **Never delete `main`, `master`, `develop`, or any protected branch.**\n- **Never force-push to a branch with an open MR** without rebasing cleanly.\n- **Always present the plan first** — no silent deletions.\n- **Check for active work** before touching any branch.\n- **Preserve local branches** the user is currently on (`git branch --show-current`).\n- **Don't delete branches newer than 7 days** — they might be in-progress work\n  that just hasn't gotten an MR yet.\n- **Prefer `git branch -d` over `-D`** for local deletions — `-d` refuses unless\n  the branch is merged, which catches \"I thought this landed but it didn't.\"\n  Only use `-D` after confirming the PR merged (squash\u002Frebase merges can leave a\n  local branch that `-d` won't recognize as merged).\n- **Don't read a successful `-d` as proof the work reached `main`.**\n  Per `git-branch(1)`, the branch must be fully merged \"in its upstream branch,\n  or in HEAD if no upstream was set\".\n  So a branch still tracking a live `origin\u002F\u003Cname>` passes on the *upstream*\n  check alone, printing `warning: deleting branch 'X' that has been merged to\n  'refs\u002Fremotes\u002Forigin\u002FX', but not yet merged to HEAD.`\n  Only a `[gone]` upstream falls back to the HEAD comparison.\n  Both outcomes are routine in one sweep (18 `-d` \u002F 11 `-D` across 29 branches\n  in one 2026-07-29 run), so whether `-d` sufficed or `-D` was required is not\n  a classification signal --- step 3 is.\n- **Never delete a local-only unpushed branch without confirmation** — if it has\n  unique commits and no remote, that work exists nowhere else.\n\n## Relationship to other skills\n\n- **`sync-pr-branch`** — used internally when rebasing stale branches\n- **`claim-pr`** — checked to avoid touching claimed branches\n- **`ardi`** — user may want to ARDI the newly opened MRs afterward\n- **`clean-worktrees` \u002F `cw`** — the worktree counterpart. This skill sweeps\n  *branches*; that one sweeps the *worktrees* a branch is checked out into. Run\n  both so neither a dead worktree nor an orphaned branch lingers.\n\n- **`clean-git`** --- the combined sweep.\n  Runs `clean-worktrees` first, then this skill,\n  because a branch held by a worktree cannot be deleted.\n\n## Anti-patterns\n\n- ❌ Deleting branches without checking for open MRs\u002Fissues first\n- ❌ Force-pushing a broken rebase\n- ❌ Touching branches that someone is actively working on\n- ❌ Deleting branches without user confirmation\n- ❌ Rebasing branches that have open MRs (use merge instead, or skip)\n","# Clean Branches (aka CB \u002F prune)\n\nAudit branches in the current repo — **both your local checkout and the\nremote**. Delete dead ones, rebase stale ones, open MRs for orphaned work, and\nsweep up local-only stragglers — all without disrupting active sessions.\n\n## When this fires\n\n- User says \"clean branches\", \"cb\", \"prune\", \"prune branches\", \"tidy up branches\"\n- User says \"clear dead branches\", \"clean up the repo\"\n- User says \"what branches can we delete?\"\n\n## Scope: local AND remote\n\nPrune in both places — they accumulate junk independently:\n\n- **Remote** branches — dead\u002Fstale\u002Forphaned remote refs (the bulk of this skill).\n- **Local** branches — branches that linger in your checkout after their PR\n  merged, or whose upstream remote was deleted (`[gone]`). The remote pass\n  alone won't catch a local branch whose remote is already gone, so there's a\n  dedicated local pass (step 8).\n\n## Definitions\n\n| Category | Criteria | Action |\n|----------|----------|--------|\n| **Dead** | Purely behind main (no unique commits ahead), no open MR, no linked issue, not created in the last 7 days | Delete |\n| **Stale** | Has unique commits ahead of main but is behind main, no recent activity (>30 days), not actively being worked on | Rebase on main, open MR if none exists |\n| **Active** | Has an open MR, linked issue, recent commits (\u003C30 days), or a claim comment | Skip — don't touch |\n| **New** | Created in the last 7 days | Skip — too fresh to judge |\n| **Local merged** | *Local* branch fully merged into main, or whose PR merged (upstream `[gone]`) | Delete locally (`git branch -d`) — step 8 |\n| **Local-only unpushed** | *Local* branch with unique commits, never pushed, no MR | Flag — ask before touching (step 8) |\n\nThe first four rows apply to **remote** branches (steps 1–7); the last two are\nthe **local** pass (step 8). A branch can need both — e.g. delete the remote ref\n*and* the leftover local tracking branch.\n\n## Procedure\n\n### 1. Detect the forge\n\n```bash\ngit remote get-url origin\n```\n\nDetermine GitHub (`gh`) vs GitLab (`glab`).\n\n### 2. Fetch and list remote branches\n\n```bash\ngit fetch --prune origin\ngit branch -r --merged origin\u002Fmain | grep -v 'origin\u002Fmain\\|origin\u002FHEAD'\ngit branch -r --no-merged origin\u002Fmain\n```\n\n**First separate real remote branches from stray ref namespaces, or the\nsweep's scope is wrong from its first command.**\nA one-off `git fetch origin '+refs\u002Fpull\u002F*\u002Fhead:refs\u002Fremotes\u002Fpr\u002F*'` writes refs\nthat no configured refspec matches, so nothing updates them and `--prune`\nnever touches them --- but `git branch -r` counts them anyway.\n\n```bash\ngit config --get-all remote.origin.fetch                                  # what is tracked\ngit for-each-ref --format='%(refname)' | grep -v '^refs\u002Fremotes\u002Forigin\u002F'  # what is not\n```\n\nAnything outside the tracked namespace is local cruft rather than a branch:\n`git push origin --delete` cannot touch it, and it belongs in a separate\n`git update-ref --stdin` sweep, not in the plan below.\n\n**Write ref patterns with `**`, because a single `*` does not cross a slash.**\n`git for-each-ref 'refs\u002Fremotes\u002Forigin\u002F*'` silently omits every slash-named\nbranch --- `feat\u002F`, `fix\u002F`, `claude\u002F` --- which is every branch anyone named\nconventionally, including the ones carrying open PRs.\nNothing errors; the count merely comes back smaller and entirely plausible.\nNote this is the **opposite** of pathspec matching, where `*` does cross a\nslash; see `memories\u002Fgit-diffing.md`, \"A ref pattern is not a pathspec\".\n\n```bash\ngit for-each-ref --format='%(refname:short)' 'refs\u002Fremotes\u002Forigin\u002F**'\n```\n\nGive the enumeration a control before trusting a total: confirm a known\nslash-named branch appears in the output.\nA shortfall here is indistinguishable from a tidy repo.\n\n### 3. Classify each branch\n\nFor each remote branch (excluding `main`, `HEAD`, protected branches):\n\n#### a. Check if it's purely behind main (merged\u002Fdead)\n\n```bash\n# Commits on branch not on main (ahead count)\ngit rev-list --count origin\u002Fmain..origin\u002F\u003Cbranch>\n\n# If 0 → branch is purely behind main (already merged or never diverged)\n```\n\n#### b. Check recency\n\n```bash\ngit log -1 --format='%ci' origin\u002F\u003Cbranch>\n```\n\nSkip if created\u002Flast-committed within the last 7 days (too new).\n\n#### c. Check for open MR\u002FPR\n\n```bash\n# GitLab\nglab mr list --source-branch=\u003Cbranch> 2>&1 | cat\n\n# GitHub\ngh pr list --head=\u003Cbranch> --json number,title,state | cat   # LIST_PRS\n```\n\nIf an open MR exists → **Active**, skip.\n\n**Fetch every PR once and match locally, rather than querying per branch.**\nA sweep of N branches costs N API round-trips this way, which is slow and\nrate-limit-prone at repo scale; one call answers for all of them, and it also\nsupplies the *merged* and *closed-unmerged* states that b and f need.\n\n```bash\ngh pr list --state all --limit 2000 \\\n  --json number,headRefName,state,mergedAt,url,title > \u002Ftmp\u002Fall-prs.json   # LIST_PRS\n```\n\nThen index by `headRefName` and look each branch up in memory.\nRaise `--limit` above the repo's total PR count and check the returned length\nagainst it --- a silently truncated list marks live branches as having no PR,\nwhich is the one error in this sweep that deletes something.\n\n#### d. Check for linked issues\n\nLook for branch naming patterns that reference issues:\n- `fix\u002F123-*`, `feat\u002F123-*`, `issue-123-*` → check if issue #123 is open\n- If the linked issue is open → **Active**, skip\n\n#### e. Check for active work claims\n\n```bash\ngh pr view \u003CN> --json comments \\\n  -q '.comments[] | select(.body | test(\"hold off|paws off|back off\"; \"i\"))\n      | select((.body | test(\"unclaim|released|PR is free|now mergeable\"; \"i\")) | not)\n      | \"\\(.author.login): \\(.body)\"'   # READ_PR_COMMENTS\n```\n\nIf a claim comment exists within the last 24 hours → **Active**, skip.\nThis window is deliberately wider than\n[`claim-pr`](..\u002F..\u002Fshared\u002Fworkflow\u002Fclaim-pr.md)'s 2-hour claim expiration:\nthat rule decides who may *start work*, where the cost of over-respecting a\ndead claim is a wait; this check gates branch *deletion*, which is\ndestructive, so it errs further toward keeping.\n\n#### f. If the PR closed unmerged, diff the branch against main before believing it\n\nCheck c only asks whether an **open** PR exists, so a branch whose PR closed\nunmerged falls straight through to a delete classification.\nThat is right for an abandoned branch and wrong for a superseded one, because a\nclosure rationale describes the PR's **stated purpose**, not an inventory of its\ndiff.\n\"Superseded by #260, all review findings addressed\" is a claim about the\nfeature; it says nothing about an unrelated fix that happened to share the\nbranch.\n\nThe gap is easy to miss in exactly the case that matters, since the rationale is\nusually accurate about the thing it names, and the leftover work is by\ndefinition the part nobody was talking about.\nNothing else flags it either: `git branch -d` consults the upstream rather than\n`main` (see the safety rules below), the superseding PR merged and closed the\nissue, and the tracker looks clean.\n\nSo for any branch whose PR closed **unmerged**, compare the files rather than\nreading the closure comment:\n\n```bash\ngh pr list --head \u003Cbranch> --state closed \\\n  --json number,title,mergedAt,url | cat                     # LIST_PRS\ngh pr diff \u003CN> --name-only                                   # DIFF_PR\ngit diff --stat origin\u002Fmain...origin\u002F\u003Cbranch>                # what is still unlanded\n```\n\n`mergedAt: null` on a closed PR is the trigger.\nThen diff each file the branch touched against `main`;\nanything still absent is unlanded work, and the branch is **Stale**, not Dead\n--- rebase it and open an MR (steps 6--7), or file an issue for the salvageable\npart and say so in the plan before deleting.\n\nWeight the check by how far the branch's contents stray from its title: a branch\ncarrying commits unrelated to the PR that named it is the shape this catches.\n`rescue-closed` is the deliberate, whole-tracker version of the same sweep; this\nis the minimum owed before a deletion.\n\n(2026-07-29: a bcs branch closed as superseded still carried an orthogonal\nout-of-memory fix --- `geepack::geeglm` replaced by `glm` + `sandwich::vcovCL`\n--- that the superseding privacy redesign never touched.\nDeleting on the closure rationale would have discarded it silently;\nfiled instead as `ucdavis\u002Fbcs#466`.)\n\n**Once you have found unlanded work, the deliverable is a tracking issue --- not\nkeeping the branch.**\nOn GitHub the branch is not the only copy: `refs\u002Fpull\u002FN\u002Fhead` is retained\npermanently and still resolves after the head branch is deleted.\nSo the choice is not \"delete or preserve\", it is \"record or lose track of\",\nwhich is a much easier call and lets the sweep finish.\n\nVerify rather than assume, since it is one call per PR, then put the recovery\ncommand in the issue:\n\n```bash\ngit ls-remote origin 'refs\u002Fpull\u002F\u003CN>\u002Fhead'    # should equal the branch tip\ngit fetch origin refs\u002Fpull\u002F\u003CN>\u002Fhead\ngit checkout -b recover\u002F\u003CN> FETCH_HEAD\n```\n\nAn issue naming what was unlanded, how much of it, and that command is strictly\nmore useful than a stale branch nobody will revisit --- and unlike the branch,\nit appears in the tracker.\n(2026-08-02, `Morrison-Lab\u002Fai-config`: six closed-unmerged branches carried\nwork absent from `main`; every `refs\u002Fpull\u002FN\u002Fhead` resolved and matched its\nbranch tip exactly, so all six were deleted after the two substantial ones were\nfiled as #1062 and #1063.)\n\n### 4. Present the plan (dry run)\n\nBefore taking any action, present a table to the user:\n\n```\n## Branch Cleanup Plan\n\n| Branch | Last commit | Status | Action |\n|--------|-------------|--------|--------|\n| `old-feature` | 2025-03-15 | Dead (merged) | 🗑️ Delete |\n| `wip-refactor` | 2025-11-20 | Stale (45 days, no MR) | 🔄 Rebase + open MR |\n| `fix\u002F42-typo` | 2026-06-15 | Active (open MR !80) | ⏭️ Skip |\n| `experiment` | 2026-06-12 | New (\u003C7 days) | ⏭️ Skip |\n\nProceed? (or pick specific branches to act on)\n```\n\nWait for user confirmation before proceeding. If user says \"just go\" or\n\"do it\", proceed with all proposed actions.\n\n### 5. Delete dead branches\n\n```bash\ngit push origin --delete \u003Cbranch>   # DELETE_REF\n```\n\nAlso clean up local tracking branches:\n```bash\ngit branch -d \u003Clocal-tracking-branch>  # if it exists locally\n```\n\n### 6. Rebase stale branches\n\nFor each stale branch:\n\n```bash\ngit checkout -B \u003Cbranch> origin\u002F\u003Cbranch>   # -B (not -b) force-resets if the branch already exists locally\ngit rebase origin\u002Fmain\n```\n\nIf rebase has conflicts:\n- Attempt to resolve automatically (see the `resolve-conflicts` skill —\n  consolidate both sides, don't blind-pick)\n- If conflicts are non-trivial, skip this branch and report it\n- Don't force-push a broken rebase\n\nIf rebase succeeds:\n```bash\ngit push --force-with-lease origin \u003Cbranch>   # PUSH\n```\n\n### 7. Open MRs for orphaned stale branches\n\nFor stale branches that have no open MR after rebasing:\n\n```bash\n# GitLab — assign to the current glab user (override ASSIGNEE to assign someone else)\nASSIGNEE=\"$(glab api user 2>\u002Fdev\u002Fnull | python3 -c \"import json,sys; print(json.load(sys.stdin)['username'])\")\"\nglab mr create --source-branch=\u003Cbranch> --target-branch=main \\\n  --title \"\u003Cinferred title from branch name>\" \\\n  --description \"Orphaned branch rebased onto main. Review or close if no longer needed.\" \\\n  ${ASSIGNEE:+--assignee \"$ASSIGNEE\"}\n\n# GitHub\ngh pr create --head=\u003Cbranch> --base=main \\\n  --title \"\u003Cinferred title>\" \\\n  --body \"Orphaned branch rebased onto main. Review or close if no longer needed.\"   # CREATE_PR\n```\n\n### 8. Prune local branches\n\nThe remote pass doesn't touch branches that only exist in your checkout. Sweep\nthose too. First refresh remote-tracking state so \"merged\" and \"gone\" are\naccurate:\n\n```bash\ngit fetch --prune origin                       # marks deleted upstreams as [gone]\ngit branch --show-current                      # never delete the branch you're on\n```\n\n**The `--prune` is a prerequisite, not a refresh --- without it step b finds\nnothing and reports success.** `[gone]` is produced *by* pruning, not by the\nbranch being deleted upstream: until a prune runs, `%(upstream:track)` is\nempty for exactly the branches b exists to find, so its `grep` matches zero\nrows and the sweep says there is nothing to clean.\nThe \"nothing found\" and \"never ran\" paths print the same thing,\nso never take a zero-row result as clean\nunless this fetch actually ran in this sweep.\n\nRecommend the standing setting once, since it makes every other tool's view\ncorrect too --- but keep the explicit `--prune` above regardless, so the sweep\ndoes not depend on the user's config:\n\n```bash\ngit config --global fetch.prune true          # or per-remote:\ngit config --global remote.origin.prune true\n```\n\nThat setting only prunes `refs\u002Fremotes\u002Forigin\u002F*`.\nIt never deletes a local branch, so it replaces none of the steps below.\n\nClassify each **local** branch (excluding `main`\u002F`master`\u002Fprotected and the\ncurrent branch):\n\n#### a. Merged into main → delete\n\n```bash\n# Branches checked out in ANY worktree cannot be deleted, and the --format\n# listing below carries no marker for them, so derive that set read-only\n# first. A per-run temp file, not a fixed \u002Ftmp name: two sessions sweeping\n# at once would otherwise read each other's set.\nCHECKED_OUT=$(mktemp); MERGED=$(mktemp); CURRENT=$(git branch --show-current)\ngit worktree list --porcelain \\\n  | awk '\u002F^branch \u002F{sub(\"refs\u002Fheads\u002F\", \"\", $2); print $2}' | sort -u > \"$CHECKED_OUT\"\n\n# The unfiltered merged list, so the two rows below can both be derived.\ngit branch --merged origin\u002Fmain --format='%(refname:short)' \\\n  | grep -vxF -e main -e master -e \"$CURRENT\" > \"$MERGED\"\n# --format gives plain names. Plain `git branch` prefixes the current branch\n# with `*` and a branch checked out in a linked worktree with `+`, so a\n# column-anchored grep on the plain listing mangled such a name into\n# `+ feature\u002Ffoo` and the delete below failed on it (ai-config#1882; the\n# clean-worktrees skill's step 3c records the same hazard). With no `*` to\n# filter, the current branch is excluded by name, per this step's contract.\n# `grep -vxF` matches whole lines literally, so a branch like\n# `maintain-docs` or `feature-main-menu` is NOT silently filtered out.\n\n# Merged but held by a linked worktree: skipped, and listed as such.\ngrep -xF -f \"$CHECKED_OUT\" \"$MERGED\"\n# Merged and free: delete candidates.\ngrep -vxF -f \"$CHECKED_OUT\" \"$MERGED\"\n# Compare against origin\u002Fmain (just fetched), NOT local `main` — your local main\n# may be behind, which would hide branches that are actually merged.\ngit branch -d \u003Cbranch>          # -d refuses if NOT actually merged — a safety net\n```\n\nA merged branch in the first list gets the status `checked out in a\nworktree` in the local plan (the step 4 table when the local rows are\nfolded into a full sweep, or the standalone local plan step 8c describes)\nand goes under \"Skipped (checked out in a worktree)\" in the step 9 report.\nClearing it is the worktree's business, not this skill's: switch that\ncheckout to another branch, or run `clean-worktrees` when the worktree is\none it would retire (it never removes the main or current worktree, and it\nskips active or fresh ones).\n`-d` (never `-D`) is deliberate: `error: the branch 'X' is not fully merged`\nmeans unmerged commits, so treat the branch as **stale**, not dead (see b).\n`error: cannot delete branch 'X' used by worktree at ...` means the\nchecked-out set went stale since it was derived; re-derive it rather than\nretrying.\n\n#### b. Upstream gone but the PR merged → delete\n\nA branch whose remote was deleted shows `[gone]`:\n\n```bash\ngit for-each-ref --format='%(refname:short) %(upstream:track)' refs\u002Fheads \\\n  | grep '\\[gone\\]'\n```\n\nFor each, confirm the PR\u002FMR actually merged before deleting (never assume):\n\n```bash\n# GitHub\ngh pr list --head \u003Cbranch> --state merged --json number,mergedAt | cat   # LIST_PRS\n\n# GitLab\nglab mr list --source-branch=\u003Cbranch> --state merged 2>&1 | cat\n```\n\n- PR merged → `git branch -D \u003Cbranch>` is acceptable here (the work landed via\n  squash\u002Frebase merge, so `-d` may not see it as merged). Confirm the merge\n  first.\n- No merged PR and unique commits exist → **stale local work**: don't delete;\n  offer to push it and open an MR (step 7 mechanics).\n\n**Read the PR, not local ancestry, to decide whether the work landed.** In a\nrepo that squash-merges --- `ucdavis\u002Fbcs` and `Morrison-Lab\u002Fai-config` both do\n--- a branch whose work is already on `main` still reports a non-zero\nahead-count, is not an ancestor of `main`, is absent from\n`git branch --merged`, and is refused by `git branch -d`.\nAll four say \"unmerged\" about a branch that merged,\nbecause the squash commit is a different commit.\nSo treat a `-d` refusal as *unproven*,\nnever as evidence the branch holds unique local work ---\nthat is what the merged-PR lookup above is for,\nand why `-D` is the right tool once it comes back positive.\n\nThe converse still holds and is what keeps this safe: no merged PR **and**\nunique commits means the work may exist nowhere else,\nso it is never deleted without confirmation.\nWhen the PR lookup is inconclusive,\ncheck content rather than ancestry, since content survives a squash:\n\n```bash\ngit show origin\u002Fmain:\u003Cpath> | grep \u003Csomething-the-branch-added>   # did it land?\n```\n\n#### c. Never pushed, has unique commits → keep, but flag\n\n```bash\ngit for-each-ref --format='%(refname:short) %(upstream)' refs\u002Fheads \\\n  | awk '$2==\"\" {print $1}'      # local branches with no upstream at all\n```\n\nReport these as \"local-only, unpushed\" and ask before doing anything — they may\nbe in-progress work that hasn't been pushed yet. Don't delete without\nconfirmation.\n\nApply the same dry-run discipline to local deletions as step 4 does for remote\nbranches — **no silent local deletions**. If you're doing a full local+remote\nsweep, fold these local rows into the step-4 plan and present them together; if\nyou're running the local pass on its own, present a standalone local plan here\nand wait for confirmation before deleting anything.\n\nA standing [`daytb`](..\u002Fdaytb\u002FSKILL.md) grant lifts this confirm step for the safe cases --- deleting a merged local branch is one of the local-git housekeeping actions that grant explicitly covers.\nThe skill's own safety preconditions are unchanged, and anything carrying commits reachable from no remote still asks.\n\n### 9. Report\n\nPrint a summary covering **both** local and remote:\n\n```\n## Branch Cleanup Complete — \u003Ctimestamp>\n\n### Deleted — remote (dead)\n- `old-feature` (last commit 2025-03-15, merged into main)\n\n### Deleted — local (merged \u002F upstream gone)\n- `add-wrap-up-skill` (PR #26 merged; local straggler)\n- `ums-session-learnings` (merged into main)\n\n### Rebased + MR opened (stale)\n- `wip-refactor` → [!85](url) (rebased, 3 commits ahead)\n\n### Skipped (active\u002Fnew)\n- `fix\u002F42-typo` — open MR !80\n- `experiment` — created 2 days ago\n\n### Skipped (checked out in a worktree)\n- `feature\u002Ffoo` (merged, but checked out at `..\u002Fwt-foo`): run `clean-worktrees` first\n\n### Flagged — local-only, unpushed (left alone)\n- `scratch-idea` — 4 unpushed commits, no MR; your call\n\n### Failed (conflicts)\n- `ancient-branch` — rebase conflicts, needs manual resolution\n```\n\n## Safety rules\n\n- **A merged PR settles that the work landed --- stop measuring there.**\n  The content checks above exist for branches whose fate is *unknown*.\n  Once `gh pr list --state merged` names a PR for the branch, residual\n  differences against `main` are the branch's pre-review draft versus the\n  post-review text that actually merged, and mean nothing about safety.\n  Measuring anyway invents doubt about the one case that is already certain:\n  in a 2026-08-02 sweep, 47 of 50 local branches had merged PRs and several\n  scored under 90% on a line-presence check purely because review had reworded\n  them.\n- **A GitHub branch is never the only copy of a PR's work.**\n  `refs\u002Fpull\u002FN\u002Fhead` is retained permanently and resolves after the head\n  branch is deleted, so \"delete the branch\" and \"lose the work\" are different\n  events on GitHub.\n  This does not weaken the local-only rule below --- a branch that was **never\n  pushed** has no PR ref behind it, and that is exactly the case that needs\n  confirmation.\n- **Never delete `main`, `master`, `develop`, or any protected branch.**\n- **Never force-push to a branch with an open MR** without rebasing cleanly.\n- **Always present the plan first** — no silent deletions.\n- **Check for active work** before touching any branch.\n- **Preserve local branches** the user is currently on (`git branch --show-current`).\n- **Don't delete branches newer than 7 days** — they might be in-progress work\n  that just hasn't gotten an MR yet.\n- **Prefer `git branch -d` over `-D`** for local deletions — `-d` refuses unless\n  the branch is merged, which catches \"I thought this landed but it didn't.\"\n  Only use `-D` after confirming the PR merged (squash\u002Frebase merges can leave a\n  local branch that `-d` won't recognize as merged).\n- **Don't read a successful `-d` as proof the work reached `main`.**\n  Per `git-branch(1)`, the branch must be fully merged \"in its upstream branch,\n  or in HEAD if no upstream was set\".\n  So a branch still tracking a live `origin\u002F\u003Cname>` passes on the *upstream*\n  check alone, printing `warning: deleting branch 'X' that has been merged to\n  'refs\u002Fremotes\u002Forigin\u002FX', but not yet merged to HEAD.`\n  Only a `[gone]` upstream falls back to the HEAD comparison.\n  Both outcomes are routine in one sweep (18 `-d` \u002F 11 `-D` across 29 branches\n  in one 2026-07-29 run), so whether `-d` sufficed or `-D` was required is not\n  a classification signal --- step 3 is.\n- **Never delete a local-only unpushed branch without confirmation** — if it has\n  unique commits and no remote, that work exists nowhere else.\n\n## Relationship to other skills\n\n- **`sync-pr-branch`** — used internally when rebasing stale branches\n- **`claim-pr`** — checked to avoid touching claimed branches\n- **`ardi`** — user may want to ARDI the newly opened MRs afterward\n- **`clean-worktrees` \u002F `cw`** — the worktree counterpart. This skill sweeps\n  *branches*; that one sweeps the *worktrees* a branch is checked out into. Run\n  both so neither a dead worktree nor an orphaned branch lingers.\n\n- **`clean-git`** --- the combined sweep.\n  Runs `clean-worktrees` first, then this skill,\n  because a branch held by a worktree cannot be deleted.\n\n## Anti-patterns\n\n- ❌ Deleting branches without checking for open MRs\u002Fissues first\n- ❌ Force-pushing a broken rebase\n- ❌ Touching branches that someone is actively working on\n- ❌ Deleting branches without user confirmation\n- ❌ Rebasing branches that have open MRs (use merge instead, or skip)\n",{"name":5,"description":7,"allowed-tools":24,"user-invocable":29},[25,26,27,28],"Bash","Read","Edit","Write",true,"main","0f720481f8ce3b3d9fef485f6e230d8b3035748e","skills\u002Fclean-branches",1,"https:\u002F\u002Fgithub.com\u002FMorrison-Lab\u002Fai-config","https:\u002F\u002Fmorrison-lab.github.io\u002Fai-config\u002F","https:\u002F\u002Fgithub.com\u002FMorrison-Lab","2026-11-15 04:39:15",{"source":8,"skillName":5,"commands":39,"prompt":49,"zipAvailable":29},[40,43,46],{"tool":41,"command":42},"npx","npx skills add Morrison-Lab\u002Fai-config --skill clean-branches",{"tool":44,"command":45},"bunx","bunx skills add Morrison-Lab\u002Fai-config --skill clean-branches",{"tool":47,"command":48},"pnpm","pnpm dlx skills add Morrison-Lab\u002Fai-config --skill clean-branches","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FMorrison-Lab\u002Fai-config\u002Fblob\u002Fmain\u002Fskills\u002Fclean-branches\u002FSKILL.md",[],[52,59,66,73,80,87],{"skillNo":53,"name":54,"nameZh":6,"description":55,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":56,"categories":57,"keywords":58,"publishedAt":19},"01M735BVYCGR5VEC65AFDVSNKW","wrap-up","End-of-session verification and UMS.","https:\u002F\u002Fgithub.com\u002FMorrison-Lab\u002Fai-config\u002Fblob\u002Fmain\u002Fskills\u002Fwrap-up\u002FSKILL.md",[],[],{"skillNo":60,"name":61,"nameZh":6,"description":62,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":63,"categories":64,"keywords":65,"publishedAt":19},"01M735BTH469T1CQ8G2Q9GENCR","workaround-watcher","Watch upstream issue for fix.","https:\u002F\u002Fgithub.com\u002FMorrison-Lab\u002Fai-config\u002Fblob\u002Fmain\u002Fskills\u002Fworkaround-watcher\u002FSKILL.md",[],[],{"skillNo":67,"name":68,"nameZh":6,"description":69,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":70,"categories":71,"keywords":72,"publishedAt":19},"01M735BRKZWFANSQ0GM380B4TD","wn","→ whats-next.","https:\u002F\u002Fgithub.com\u002FMorrison-Lab\u002Fai-config\u002Fblob\u002Fmain\u002Fskills\u002Fwn\u002FSKILL.md",[],[],{"skillNo":74,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":19},"01M735BPE9V830B3B6NGXQ56J6","whats-next","Recommend concrete next step or action.","https:\u002F\u002Fgithub.com\u002FMorrison-Lab\u002Fai-config\u002Fblob\u002Fmain\u002Fskills\u002Fwhats-next\u002FSKILL.md",[],[],{"skillNo":81,"name":82,"nameZh":6,"description":83,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":19},"01M735BMHQ60EAD5B7QAWXC5A0","wait-for-results","Wait for pipeline\u002FCI results.","https:\u002F\u002Fgithub.com\u002FMorrison-Lab\u002Fai-config\u002Fblob\u002Fmain\u002Fskills\u002Fwait-for-results\u002FSKILL.md",[],[],{"skillNo":88,"name":89,"nameZh":6,"description":90,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":91,"categories":92,"keywords":93,"publishedAt":19},"01M735BKGZHPN1PEMJ7YBD5VJ8","wai","→ send-notes.","https:\u002F\u002Fgithub.com\u002FMorrison-Lab\u002Fai-config\u002Fblob\u002Fmain\u002Fskills\u002Fwai\u002FSKILL.md",[],[]]