Branch Lifecycle
Invoke as $branch-lifecycle.
Evaluate feature branches after review and drive one of four outcomes: merge, salvage, keep-open, or delete.
This is a compatibility and advanced-recovery wrapper. Normal issue-backed branch creation/publication delegates to $github-branch; pull-request creation, review, and merge delegate to $github-pr. This skill retains inventory, salvage, and cleanup decisions for legacy or damaged branch state.
Arguments
- No args or
list: inventory candidate branches and recommend an action for each.
pr [branch...]: create PRs for branches that do not already have one and pass basic readiness checks.
review <branch-or-pr>: classify a branch or PR as merge, salvage, keep-open, or delete.
merge <branch-or-pr>: merge only if the strict merge gate passes.
salvage <branch-or-pr> [--onto <base>] [--commits <sha,...>]: cherry-pick selected commits onto a fresh target branch.
cleanup: delete merged branches and prompt for stale unmerged branches.
--force: skip confirmations for safe-destructive actions (PR creation, approved merge, merged-branch deletion). Never skips confirmation for deleting an unmerged branch.
Process
Resolve repository context:
- Detect the base branch in this order: repository default branch,
main, then master.
- Run
git status and report uncommitted changes before any mutating action.
- Use
gh for PR metadata and merge operations when available. If gh is unavailable or unauthenticated, report that limitation and continue with local-only facts where possible.
- State clearly that normal tracked mutations use an issue-backed non-primary branch and ready pull request.
Build branch inventory:
- Enumerate local branches except the current branch and base branch.
- For each branch, gather:
- Ahead/behind counts vs base:
git rev-list --left-right --count <base>...<branch>
- Last commit date/author:
git log -1 --format="%cr|%an" <branch>
- Unique commits vs base:
git log --reverse --oneline <base>..<branch>
- PR status and checks, when a PR exists
- Flag a branch as stale when it has no open PR and its last commit is older than 30 days.
Apply the decision policy:
- Merge only when all strict-gate checks pass:
- focused scope
- passing CI/tests or no required checks
- no merge conflicts
- approval requirements satisfied, or no required review
- no unresolved high-severity review findings
- Salvage when the branch is outdated, mixed in scope, or not merge-ready but contains specific commits worth keeping.
- Keep-open when the branch is active and still worth finishing on its current line of development.
- Delete when the branch is stale or below standards and no clearly valuable commits remain.
- Increase confidence in a
delete recommendation when stale is combined with any of:
- behind base by 10 or more commits
- failing or missing checks on an abandoned PR
- obviously mixed or abandoned scope
Execute the requested subcommand using the rules below.
Subcommand Actions
list
- Print a table with:
- branch
- age
- ahead/behind
- PR status
- checks
- recommendation
- Use
merge, salvage, keep-open, or delete in the recommendation column.
- Include a brief reason for non-merge recommendations, such as
stale, mixed scope, behind base, or failing checks.
pr [branch...]
- Use the supplied branches, or find local branches without an open PR.
- Refuse to create a PR for:
- the current branch
- the base branch
- branches already marked
delete
- For each eligible branch:
- summarize commits unique to the branch
- confirm with the user unless
--force
- delegate PR reuse/creation to
$github-pr upsert
- If a branch is a better
salvage candidate than a PR candidate, say so and do not open the PR automatically.
review <branch-or-pr>
- Resolve the target to a branch and, if present, its PR.
- Evaluate:
- scope focus
- CI/tests
- conflicts
- approval state
- stale status
- whether the branch contains a small set of clearly reusable commits
- Output:
- target summary
- branch facts
- findings
- recommended action:
merge, salvage, keep-open, or delete
- the reason tied to the decision policy
merge <branch-or-pr>
- Resolve the target to an open PR. If the branch has no PR, stop and recommend
pr or salvage.
- Re-check the strict merge gate.
- If any merge gate fails, stop and explain which requirement failed.
- Delegate the final gate, explicit confirmation, and merge to
$github-pr merge <number>; --force never bypasses that merge confirmation.
- Report the merged PR and resulting commit hash.
salvage <branch-or-pr> [--onto <base>] [--commits <sha,...>]
- Resolve the source branch and target base branch.
- Default target base is the detected repository base branch.
- If
--onto is provided, use that branch as the target base.
- Show the commit list unique to the source branch in chronological order.
- Determine which commits to keep:
- if
--commits is provided, use those SHAs in the given order
- otherwise, ask the user to choose commits explicitly
- Create a fresh target branch from the chosen base, using a name derived from the source branch such as
salvage/<source>-<date>.
- Cherry-pick the selected commits in order.
- If a conflict occurs:
- stop immediately
- report the conflicted files and the standard
git cherry-pick --continue / --abort next steps
- do not auto-resolve or continue
- Report the new branch name and the preserved commits.
- Never delete the source branch automatically after salvage.
cleanup
- Find merged branches and confirm deletion unless
--force.
- Delete local merged branches with
git branch -d.
- If the matching remote branch exists, delete it too after the same confirmation scope.
- Identify stale unmerged branches and print their recommendation reasons.
- Ask for confirmation before deleting each unmerged branch individually.
- Even with
--force, never auto-delete an unmerged branch.
- If a stale branch looks salvageable, recommend
salvage instead of deleting it immediately.
Constraints
- Never force-push or rewrite history.
- Never merge a PR that fails the strict gate.
- Never auto-delete an unmerged branch.
- Never auto-delete a source branch after salvage.
- Never cherry-pick the full branch implicitly; salvage is commit-selective by default.
- If the working tree is dirty and the requested action is mutating, warn first and stop unless the user explicitly wants to continue.
- Prefer reporting and stopping over making branch-history decisions silently.
Alignment Page
Follow the shared alignment-page convention via the packaged convention resolver; output path is alignment/branch-lifecycle-{topic}.html. By default, report results inline and write only this skill's normal durable artifacts; create an alignment page only when explicitly requested or when a concrete clarification/review need cannot be handled cleanly inline.
Default Shipping Contract
Follow the shared shipping contract convention in CLAUDE.md.
1---2name: branch-lifecycle3description: Evaluate feature branches and decide whether to merge, salvage, keep open, or delete based on branch health, PR status, and stale-branch heuristics4---5
6# Branch Lifecycle
7
8Invoke as `$branch-lifecycle`.
9
10Evaluate feature branches after review and drive one of four outcomes: `merge`, `salvage`, `keep-open`, or `delete`.
11
12This is a compatibility and advanced-recovery wrapper. Normal issue-backed branch creation/publication delegates to `$github-branch`; pull-request creation, review, and merge delegate to `$github-pr`. This skill retains inventory, salvage, and cleanup decisions for legacy or damaged branch state.
13
14## Arguments
15
16- **No args** or **`list`**: inventory candidate branches and recommend an action for each.
17- **`pr [branch...]`**: create PRs for branches that do not already have one and pass basic readiness checks.
18- **`review <branch-or-pr>`**: classify a branch or PR as `merge`, `salvage`, `keep-open`, or `delete`.
19- **`merge <branch-or-pr>`**: merge only if the strict merge gate passes.
20- **`salvage <branch-or-pr> [--onto <base>] [--commits <sha,...>]`**: cherry-pick selected commits onto a fresh target branch.
21- **`cleanup`**: delete merged branches and prompt for stale unmerged branches.
22- **`--force`**: skip confirmations for safe-destructive actions (PR creation, approved merge, merged-branch deletion). Never skips confirmation for deleting an unmerged branch.
23
24## Process
25
261. **Resolve repository context:**
27 - Detect the base branch in this order: repository default branch, `main`, then `master`.
28 - Run `git status` and report uncommitted changes before any mutating action.
29 - Use `gh` for PR metadata and merge operations when available. If `gh` is unavailable or unauthenticated, report that limitation and continue with local-only facts where possible.
30 - State clearly that normal tracked mutations use an issue-backed non-primary branch and ready pull request.
31
322. **Build branch inventory:**
33 - Enumerate local branches except the current branch and base branch.
34 - For each branch, gather:
35 - Ahead/behind counts vs base: `git rev-list --left-right --count <base>...<branch>`
36 - Last commit date/author: `git log -1 --format="%cr|%an" <branch>`
37 - Unique commits vs base: `git log --reverse --oneline <base>..<branch>`
38 - PR status and checks, when a PR exists
39 - Flag a branch as **stale** when it has no open PR and its last commit is older than 30 days.
40
413. **Apply the decision policy:**
42 - **Merge** only when all strict-gate checks pass:
43 - focused scope
44 - passing CI/tests or no required checks
45 - no merge conflicts
46 - approval requirements satisfied, or no required review
47 - no unresolved high-severity review findings
48 - **Salvage** when the branch is outdated, mixed in scope, or not merge-ready but contains specific commits worth keeping.
49 - **Keep-open** when the branch is active and still worth finishing on its current line of development.
50 - **Delete** when the branch is stale or below standards and no clearly valuable commits remain.
51 - Increase confidence in a `delete` recommendation when stale is combined with any of:
52 - behind base by 10 or more commits
53 - failing or missing checks on an abandoned PR
54 - obviously mixed or abandoned scope
55
564. **Execute the requested subcommand** using the rules below.
57
58## Subcommand Actions
59
60### `list`
61
621. Print a table with:
63 - branch
64 - age
65 - ahead/behind
66 - PR status
67 - checks
68 - recommendation
692. Use `merge`, `salvage`, `keep-open`, or `delete` in the recommendation column.
703. Include a brief reason for non-merge recommendations, such as `stale`, `mixed scope`, `behind base`, or `failing checks`.
71
72### `pr [branch...]`
73
741. Use the supplied branches, or find local branches without an open PR.
752. Refuse to create a PR for:
76 - the current branch
77 - the base branch
78 - branches already marked `delete`
793. For each eligible branch:
80 - summarize commits unique to the branch
81 - confirm with the user unless `--force`
82 - delegate PR reuse/creation to `$github-pr upsert`
834. If a branch is a better `salvage` candidate than a PR candidate, say so and do not open the PR automatically.
84
85### `review <branch-or-pr>`
86
871. Resolve the target to a branch and, if present, its PR.
882. Evaluate:
89 - scope focus
90 - CI/tests
91 - conflicts
92 - approval state
93 - stale status
94 - whether the branch contains a small set of clearly reusable commits
953. Output:
96 - target summary
97 - branch facts
98 - findings
99 - recommended action: `merge`, `salvage`, `keep-open`, or `delete`
100 - the reason tied to the decision policy
101
102### `merge <branch-or-pr>`
103
1041. Resolve the target to an open PR. If the branch has no PR, stop and recommend `pr` or `salvage`.
1052. Re-check the strict merge gate.
1063. If any merge gate fails, stop and explain which requirement failed.
1074. Delegate the final gate, explicit confirmation, and merge to `$github-pr merge <number>`; `--force` never bypasses that merge confirmation.
1085. Report the merged PR and resulting commit hash.
109
110### `salvage <branch-or-pr> [--onto <base>] [--commits <sha,...>]`
111
1121. Resolve the source branch and target base branch.
113 - Default target base is the detected repository base branch.
114 - If `--onto` is provided, use that branch as the target base.
1152. Show the commit list unique to the source branch in chronological order.
1163. Determine which commits to keep:
117 - if `--commits` is provided, use those SHAs in the given order
118 - otherwise, ask the user to choose commits explicitly
1194. Create a fresh target branch from the chosen base, using a name derived from the source branch such as `salvage/<source>-<date>`.
1205. Cherry-pick the selected commits in order.
1216. If a conflict occurs:
122 - stop immediately
123 - report the conflicted files and the standard `git cherry-pick --continue` / `--abort` next steps
124 - do not auto-resolve or continue
1257. Report the new branch name and the preserved commits.
1268. Never delete the source branch automatically after salvage.
127
128### `cleanup`
129
1301. Find merged branches and confirm deletion unless `--force`.
1312. Delete local merged branches with `git branch -d`.
1323. If the matching remote branch exists, delete it too after the same confirmation scope.
1334. Identify stale unmerged branches and print their recommendation reasons.
1345. Ask for confirmation before deleting each unmerged branch individually.
135 - Even with `--force`, never auto-delete an unmerged branch.
1366. If a stale branch looks salvageable, recommend `salvage` instead of deleting it immediately.
137
138## Constraints
139
140- Never force-push or rewrite history.
141- Never merge a PR that fails the strict gate.
142- Never auto-delete an unmerged branch.
143- Never auto-delete a source branch after salvage.
144- Never cherry-pick the full branch implicitly; salvage is commit-selective by default.
145- If the working tree is dirty and the requested action is mutating, warn first and stop unless the user explicitly wants to continue.
146- Prefer reporting and stopping over making branch-history decisions silently.
147
148
149## Alignment Page
150
151Follow the shared alignment-page convention via the packaged convention resolver; output path is `alignment/branch-lifecycle-{topic}.html`. By default, report results inline and write only this skill's normal durable artifacts; create an alignment page only when explicitly requested or when a concrete clarification/review need cannot be handled cleanly inline.
152
153## Default Shipping Contract
154
155Follow the shared shipping contract convention in CLAUDE.md.