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-lifecycle
3description: "Evaluate feature branches and decide whether to merge, salvage, keep open, or delete based on branch health, PR status, and stale-branch heuristics"
4type: ops
5version: v0.3
6required_conventions: [alignment-page]
7argument-hint: "[--force] [list | pr [branch...] | review <branch-or-pr> | merge <branch-or-pr> | salvage <branch-or-pr> [--onto <base>] [--commits <sha,...>] | cleanup]"
8metadata:
9 source: https://skillmd.com/skills/georgeqle/branch-lifecycle
10---
11
12# Branch Lifecycle
13
14Invoke as `$branch-lifecycle`.
15
16Evaluate feature branches after review and drive one of four outcomes: `merge`, `salvage`, `keep-open`, or `delete`.
17
18This 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.
19
20## Arguments
21
22- **No args** or **`list`**: inventory candidate branches and recommend an action for each.
23- **`pr [branch...]`**: create PRs for branches that do not already have one and pass basic readiness checks.
24- **`review <branch-or-pr>`**: classify a branch or PR as `merge`, `salvage`, `keep-open`, or `delete`.
25- **`merge <branch-or-pr>`**: merge only if the strict merge gate passes.
26- **`salvage <branch-or-pr> [--onto <base>] [--commits <sha,...>]`**: cherry-pick selected commits onto a fresh target branch.
27- **`cleanup`**: delete merged branches and prompt for stale unmerged branches.
28- **`--force`**: skip confirmations for safe-destructive actions (PR creation, approved merge, merged-branch deletion). Never skips confirmation for deleting an unmerged branch.
29
30## Process
31
321. **Resolve repository context:**
33 - Detect the base branch in this order: repository default branch, `main`, then `master`.
34 - Run `git status` and report uncommitted changes before any mutating action.
35 - 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.
36 - State clearly that normal tracked mutations use an issue-backed non-primary branch and ready pull request.
37
382. **Build branch inventory:**
39 - Enumerate local branches except the current branch and base branch.
40 - For each branch, gather:
41 - Ahead/behind counts vs base: `git rev-list --left-right --count <base>...<branch>`
42 - Last commit date/author: `git log -1 --format="%cr|%an" <branch>`
43 - Unique commits vs base: `git log --reverse --oneline <base>..<branch>`
44 - PR status and checks, when a PR exists
45 - Flag a branch as **stale** when it has no open PR and its last commit is older than 30 days.
46
473. **Apply the decision policy:**
48 - **Merge** only when all strict-gate checks pass:
49 - focused scope
50 - passing CI/tests or no required checks
51 - no merge conflicts
52 - approval requirements satisfied, or no required review
53 - no unresolved high-severity review findings
54 - **Salvage** when the branch is outdated, mixed in scope, or not merge-ready but contains specific commits worth keeping.
55 - **Keep-open** when the branch is active and still worth finishing on its current line of development.
56 - **Delete** when the branch is stale or below standards and no clearly valuable commits remain.
57 - Increase confidence in a `delete` recommendation when stale is combined with any of:
58 - behind base by 10 or more commits
59 - failing or missing checks on an abandoned PR
60 - obviously mixed or abandoned scope
61
624. **Execute the requested subcommand** using the rules below.
63
64## Subcommand Actions
65
66### `list`
67
681. Print a table with:
69 - branch
70 - age
71 - ahead/behind
72 - PR status
73 - checks
74 - recommendation
752. Use `merge`, `salvage`, `keep-open`, or `delete` in the recommendation column.
763. Include a brief reason for non-merge recommendations, such as `stale`, `mixed scope`, `behind base`, or `failing checks`.
77
78### `pr [branch...]`
79
801. Use the supplied branches, or find local branches without an open PR.
812. Refuse to create a PR for:
82 - the current branch
83 - the base branch
84 - branches already marked `delete`
853. For each eligible branch:
86 - summarize commits unique to the branch
87 - confirm with the user unless `--force`
88 - delegate PR reuse/creation to `$github-pr upsert`
894. If a branch is a better `salvage` candidate than a PR candidate, say so and do not open the PR automatically.
90
91### `review <branch-or-pr>`
92
931. Resolve the target to a branch and, if present, its PR.
942. Evaluate:
95 - scope focus
96 - CI/tests
97 - conflicts
98 - approval state
99 - stale status
100 - whether the branch contains a small set of clearly reusable commits
1013. Output:
102 - target summary
103 - branch facts
104 - findings
105 - recommended action: `merge`, `salvage`, `keep-open`, or `delete`
106 - the reason tied to the decision policy
107
108### `merge <branch-or-pr>`
109
1101. Resolve the target to an open PR. If the branch has no PR, stop and recommend `pr` or `salvage`.
1112. Re-check the strict merge gate.
1123. If any merge gate fails, stop and explain which requirement failed.
1134. Delegate the final gate, explicit confirmation, and merge to `$github-pr merge <number>`; `--force` never bypasses that merge confirmation.
1145. Report the merged PR and resulting commit hash.
115
116### `salvage <branch-or-pr> [--onto <base>] [--commits <sha,...>]`
117
1181. Resolve the source branch and target base branch.
119 - Default target base is the detected repository base branch.
120 - If `--onto` is provided, use that branch as the target base.
1212. Show the commit list unique to the source branch in chronological order.
1223. Determine which commits to keep:
123 - if `--commits` is provided, use those SHAs in the given order
124 - otherwise, ask the user to choose commits explicitly
1254. Create a fresh target branch from the chosen base, using a name derived from the source branch such as `salvage/<source>-<date>`.
1265. Cherry-pick the selected commits in order.
1276. If a conflict occurs:
128 - stop immediately
129 - report the conflicted files and the standard `git cherry-pick --continue` / `--abort` next steps
130 - do not auto-resolve or continue
1317. Report the new branch name and the preserved commits.
1328. Never delete the source branch automatically after salvage.
133
134### `cleanup`
135
1361. Find merged branches and confirm deletion unless `--force`.
1372. Delete local merged branches with `git branch -d`.
1383. If the matching remote branch exists, delete it too after the same confirmation scope.
1394. Identify stale unmerged branches and print their recommendation reasons.
1405. Ask for confirmation before deleting each unmerged branch individually.
141 - Even with `--force`, never auto-delete an unmerged branch.
1426. If a stale branch looks salvageable, recommend `salvage` instead of deleting it immediately.
143
144## Constraints
145
146- Never force-push or rewrite history.
147- Never merge a PR that fails the strict gate.
148- Never auto-delete an unmerged branch.
149- Never auto-delete a source branch after salvage.
150- Never cherry-pick the full branch implicitly; salvage is commit-selective by default.
151- If the working tree is dirty and the requested action is mutating, warn first and stop unless the user explicitly wants to continue.
152- Prefer reporting and stopping over making branch-history decisions silently.
153
154
155## Alignment Page
156
157Follow 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.
158
159## Default Shipping Contract
160
161Follow the shared shipping contract convention in CLAUDE.md.