Skill Tracer
Skills › Superpowers › finishing-a-development-branch

finishing-a-development-branch

skill · 225 lines · MIT · skills/finishing-a-development-branch/SKILL.md

The facts

Its description

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work

The description the agent reads to decide when to use it.

From its settingsline 3

When it starts

The agent reaches for this skill at the end of a piece of work: the implementation is done, the test suite is green, and the branch still has to be landed somehow. It is a closing step, so it fires after the coding is finished rather than at the start of a task.

Things a person might say (the model's guesses)

  • “The feature's done and all the tests pass — how do you want to land this branch?”
  • “I've finished the refactor on my feature branch. Should we merge it to main or open a PR?”
  • “Everything's green now. What should we do with this branch?”

A model's summary of when it is used.

A model's reading

Stops for a person

2 lines stop to ask a person

Lines that stop and wait for a person before going on. Found by matching words, so treat them as pointers.

Found by matching wordsline 81 line 217

What leads to it

Other skills that hand off to this one, call it, require it or offer it instead, as a model read them.

A model's reading

Licence

MIT, from LICENSE

The terms its author shares it under, which let it be shown here.

From the repositorylicence text

The text

Open on GitHub

Most marks come from matching words in the file, so treat them as pointers.

1---
2name: finishing-a-development-branch
3description: Use when implementation is complete, all tests pass, and you need to decide how to integrate the work
4---
5
6# Finishing a Development Branch
7

Finishing a Development Branch

Raw lines 1 to 7
8## Overview
9
10**Core principle:** Verify tests → Detect environment → Present options → Execute choice → Clean up.
12**Announce at start:** "I'm using the finishing-a-development-branch skill to complete this work."

Overview

Core principle: Verify tests → Detect environment → Present options → Execute choice → Clean up.

Announce at start: "I'm using the finishing-a-development-branch skill to complete this work."

Raw lines 8 to 13
14## Step 1: Verify Tests
16Run the project's full test suite (`npm test` / `cargo test` / `pytest` / `go test ./...`).
18**If tests fail**, report the failures and stop — the menu comes after a green suite:
20```
21Tests failing (<N> failures). Must fix before completing:
23[Show failures]
24```
26**If tests pass:** continue to Step 2.

Step 1: Verify Tests

Run the project's full test suite (npm test / cargo test / pytest / go test ./...).

If tests fail, report the failures and stop — the menu comes after a green suite:

Tests failing (<N> failures). Must fix before completing:

[Show failures]

If tests pass: continue to Step 2.

Raw lines 14 to 27
28## Step 2: Detect Environment
30```bash
31GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P)
32GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P)
33# Capture now, while still inside the workspace — Step 5 changes directory
34# before cleanup (Step 6) needs this value
35WORKTREE_PATH=$(git rev-parse --show-toplevel)
36```
38This determines which menu to show and how cleanup works:
40| State | Menu | Cleanup |
41|-------|------|---------|
42| `GIT_DIR == GIT_COMMON` (normal repo) | Standard 3 options | No worktree to clean up |
43| `GIT_DIR != GIT_COMMON`, named branch | Standard 3 options | Provenance-based (see Step 6) |
44| `GIT_DIR != GIT_COMMON`, detached HEAD | Reduced 2 options (no merge) | Externally managed — leave in place |

Step 2: Detect Environment

GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P)
GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P)
# Capture now, while still inside the workspace — Step 5 changes directory
# before cleanup (Step 6) needs this value
WORKTREE_PATH=$(git rev-parse --show-toplevel)

This determines which menu to show and how cleanup works:

StateMenuCleanup
GIT_DIR == GIT_COMMON (normal repo)Standard 3 optionsNo worktree to clean up
GIT_DIR != GIT_COMMON, named branchStandard 3 optionsProvenance-based (see Step 6)
GIT_DIR != GIT_COMMON, detached HEADReduced 2 options (no merge)Externally managed — leave in place
Raw lines 28 to 45
46## Step 3: Determine Base Branch
48The base branch is whatever this work forked from — usually named in the
49plan, the conversation, or the branch's upstream. If it is not already
50known, ask: "This branch split from <your best guess> - is that correct?"
51Confirm before merging: merging into the wrong base is expensive to undo.

Step 3: Determine Base Branch

The base branch is whatever this work forked from — usually named in the plan, the conversation, or the branch's upstream. If it is not already known, ask: "This branch split from <your best guess> - is that correct?" Confirm before merging: merging into the wrong base is expensive to undo.

Raw lines 46 to 52
53## Step 4: Present Options
55**Normal repo and named-branch worktree — present exactly these 3 options:**
57```
58Implementation complete. What would you like to do?
601. Merge back to <base-branch> locally
612. Push and create a Pull Request
623. Keep the branch as-is (I'll handle it later)
64Which option?
65```
67**Detached HEAD — present exactly these 2 options:**
69```
70Implementation complete. You're on a detached HEAD (externally managed workspace).
721. Push as new branch and create a Pull Request
732. Keep as-is (I'll handle it later)
75Which option?
76```
78Present the menu exactly as written — concise, with every option coming
79from the list above. Discarding the work happens only in response to your
80human partner explicitly asking for it (see "If your human partner asks to
81discard the work" below). Wait for their answer; the integration decision
82is theirs.

Step 4: Present Options

Normal repo and named-branch worktree — present exactly these 3 options:

Implementation complete. What would you like to do?

1. Merge back to <base-branch> locally
2. Push and create a Pull Request
3. Keep the branch as-is (I'll handle it later)

Which option?

Detached HEAD — present exactly these 2 options:

Implementation complete. You're on a detached HEAD (externally managed workspace).

1. Push as new branch and create a Pull Request
2. Keep as-is (I'll handle it later)

Which option?

Present the menu exactly as written — concise, with every option coming from the list above. Discarding the work happens only in response to your human partner explicitly asking for it (see "If your human partner asks to discard the work" below). Wait for their answer; the integration decision is theirs.

Raw lines 53 to 83
Involves a person Wait for their :81
84## Step 5: Execute Choice

Step 5: Execute Choice

Raw lines 84 to 85
86### Option 1: Merge Locally
88```bash
89# Get main repo root for CWD safety
90MAIN_ROOT=$(git -C "$(git rev-parse --git-common-dir)/.." rev-parse --show-toplevel)
91cd "$MAIN_ROOT"
93# Merge first — verify success before removing anything
94git checkout <base-branch>
95git pull
96git merge <feature-branch>
98# Verify tests on merged result
99<test command>
100```
102If tests fail on the merged result: stop, leave the worktree and branch in
103place, and investigate — nothing has been pushed, so the merge is local
104and recoverable.
106Once the merged result is green: clean up the worktree (Step 6), then
107delete the branch:
109```bash
110git branch -d <feature-branch>
111```

Option 1: Merge Locally

# Get main repo root for CWD safety
MAIN_ROOT=$(git -C "$(git rev-parse --git-common-dir)/.." rev-parse --show-toplevel)
cd "$MAIN_ROOT"

# Merge first — verify success before removing anything
git checkout <base-branch>
git pull
git merge <feature-branch>

# Verify tests on merged result
<test command>

If tests fail on the merged result: stop, leave the worktree and branch in place, and investigate — nothing has been pushed, so the merge is local and recoverable.

Once the merged result is green: clean up the worktree (Step 6), then delete the branch:

git branch -d <feature-branch>
Raw lines 86 to 112
113### Option 2: Push and Create PR
115```bash
116git push -u origin <feature-branch>
117# From a detached HEAD, name the new branch on the remote:
118# git push origin HEAD:refs/heads/<new-branch>
119```
121Then create the pull/merge request against <base-branch> with the forge's
122tooling — its CLI if one is available, or the creation URL most forges
123print when you push — following the repo's PR template and conventions if
124present, and report the URL to your human partner.
126Keep the worktree — your human partner iterates on PR feedback there.

Option 2: Push and Create PR

git push -u origin <feature-branch>
# From a detached HEAD, name the new branch on the remote:
# git push origin HEAD:refs/heads/<new-branch>

Then create the pull/merge request against <base-branch> with the forge's tooling — its CLI if one is available, or the creation URL most forges print when you push — following the repo's PR template and conventions if present, and report the URL to your human partner.

Keep the worktree — your human partner iterates on PR feedback there.

Raw lines 113 to 127
128### Option 3: Keep As-Is
130Report: "Keeping branch <name>. Worktree preserved at <path>."

Option 3: Keep As-Is

Report: "Keeping branch <name>. Worktree preserved at <path>."

Raw lines 128 to 131
132### If your human partner asks to discard the work
134This path exists only as a response to an explicit request to throw the
135work away. Confirm first:
137```
138This will permanently delete:
139- Branch <name>
140- All commits: <commit-list>
141- Worktree at <path>
143Type 'discard' to confirm.
144```
146Wait for that exact confirmation. When it arrives:
148```bash
149MAIN_ROOT=$(git -C "$(git rev-parse --git-common-dir)/.." rev-parse --show-toplevel)
150cd "$MAIN_ROOT"
151```
153Then clean up the worktree (Step 6) and force-delete the branch:
155```bash
156git branch -D <feature-branch>
157```

If your human partner asks to discard the work

This path exists only as a response to an explicit request to throw the work away. Confirm first:

This will permanently delete:
- Branch <name>
- All commits: <commit-list>
- Worktree at <path>

Type 'discard' to confirm.

Wait for that exact confirmation. When it arrives:

MAIN_ROOT=$(git -C "$(git rev-parse --git-common-dir)/.." rev-parse --show-toplevel)
cd "$MAIN_ROOT"

Then clean up the worktree (Step 6) and force-delete the branch:

git branch -D <feature-branch>
Raw lines 132 to 158
159## Step 6: Cleanup Workspace
161**Runs for Option 1 and confirmed discards.** Options 2 and 3 always
162preserve the worktree. Both callers have already changed directory to the
163main repo root — worktree removal must run from outside the worktree —
164and use the `GIT_DIR`/`GIT_COMMON`/`WORKTREE_PATH` values captured in
165Step 2, from before that directory change.
167**If `GIT_DIR == GIT_COMMON`:** Normal repo, no worktree to clean up. Done.
169**If `WORKTREE_PATH` is under `.worktrees/` or `worktrees/`:** Superpowers
172```bash
173git worktree remove "$WORKTREE_PATH"
174git worktree prune # Self-healing: clean up any stale registrations
175```
177**If removal is refused** (`contains modified or untracked files`): the
178worktree holds files that exist nowhere else — uncommitted plans, notes,
179or scratch work. Never `--force` on your own initiative. Show your human
180partner what is at stake and ask:
182```bash
183git -C "$WORKTREE_PATH" status --porcelain -uall
184```
186```
187Worktree removal refused — these files were never committed:
189<file list>
1911. Commit them to <branch> before cleanup
1922. Move them into <main repo root>
1933. Delete them (unrecoverable)
195Which?
196```
198Carry out the choice, then remove the worktree.
200**Otherwise:** The host environment owns this workspace — leave it in
201place. If your platform provides a workspace-exit tool, use it.

Step 6: Cleanup Workspace

Runs for Option 1 and confirmed discards. Options 2 and 3 always preserve the worktree. Both callers have already changed directory to the main repo root — worktree removal must run from outside the worktree — and use the GIT_DIR/GIT_COMMON/WORKTREE_PATH values captured in Step 2, from before that directory change.

**If GIT_DIR == GIT_COMMON:** Normal repo, no worktree to clean up. Done.

**If WORKTREE_PATH is under .worktrees/ or worktrees/:** Superpowers created this worktree — we own cleanup:

git worktree remove "$WORKTREE_PATH"
git worktree prune  # Self-healing: clean up any stale registrations

If removal is refused (contains modified or untracked files): the worktree holds files that exist nowhere else — uncommitted plans, notes, or scratch work. Never --force on your own initiative. Show your human partner what is at stake and ask:

git -C "$WORKTREE_PATH" status --porcelain -uall
Worktree removal refused — these files were never committed:

<file list>

1. Commit them to <branch> before cleanup
2. Move them into <main repo root>
3. Delete them (unrecoverable)

Which?

Carry out the choice, then remove the worktree.

Otherwise: The host environment owns this workspace — leave it in place. If your platform provides a workspace-exit tool, use it.

Raw lines 159 to 202
Names a skill using-git-worktrees :170
203## Quick Reference
205| Option | Merge | Push | Keep Worktree | Cleanup Branch |
206|--------|-------|------|---------------|----------------|
207| 1. Merge locally | yes | - | - | yes |
208| 2. Create PR | - | yes | yes | - |
209| 3. Keep as-is | - | - | yes | - |
210| Discard (explicit request only) | - | - | - | yes (force) |

Quick Reference

OptionMergePushKeep WorktreeCleanup Branch
1. Merge locallyyes--yes
2. Create PR-yesyes-
3. Keep as-is--yes-
Discard (explicit request only)---yes (force)
Raw lines 203 to 211
212## Common Rationalizations
214| Excuse | Reality |
215|--------|---------|
216| "Tests passed earlier this session" | Run the suite on the tree you are about to integrate. A green run only proves the tree it ran on. |
217| "They obviously want it merged" | Integration is your human partner's decision. Present the menu and wait. |
218| "They seem done with this feature — I'll offer to discard it" | The menu is complete as written. Discard happens only when your human partner asks for it in so many words. |
219| "'Yeah, get rid of it' counts as confirmation" | Only the typed word `discard` authorizes deletion. |
220| "The PR is up, so the worktree is clutter now" | PR feedback gets fixed in that worktree. It stays until the work lands. |
221| "This other worktree looks stale — I'll clean it too" | Clean up only worktrees under `.worktrees/` or `worktrees/`. Everything else belongs to the host. |
222| "Removal refused — `--force` is just finishing the cleanup" | The refusal means files exist only in that worktree. `--force` destroys them permanently. Show your human partner and ask. |
223| "The merged-result failure is probably flaky" | A failing merged result stops everything. Branch and worktree stay put while you investigate. |
224| "The base branch is obviously main" | Confirm the fork point or ask. Merging into the wrong base is expensive to undo. |
225| "The push was rejected — force-push will fix it" | A rejected push means the remote moved. Investigate; force-push only on your human partner's explicit request. |

Common Rationalizations

ExcuseReality
"Tests passed earlier this session"Run the suite on the tree you are about to integrate. A green run only proves the tree it ran on.
"They obviously want it merged"Integration is your human partner's decision. Present the menu and wait.
"They seem done with this feature — I'll offer to discard it"The menu is complete as written. Discard happens only when your human partner asks for it in so many words.
"'Yeah, get rid of it' counts as confirmation"Only the typed word discard authorizes deletion.
"The PR is up, so the worktree is clutter now"PR feedback gets fixed in that worktree. It stays until the work lands.
"This other worktree looks stale — I'll clean it too"Clean up only worktrees under .worktrees/ or worktrees/. Everything else belongs to the host.
"Removal refused — --force is just finishing the cleanup"The refusal means files exist only in that worktree. --force destroys them permanently. Show your human partner and ask.
"The merged-result failure is probably flaky"A failing merged result stops everything. Branch and worktree stay put while you investigate.
"The base branch is obviously main"Confirm the fork point or ask. Merging into the wrong base is expensive to undo.
"The push was rejected — force-push will fix it"A rejected push means the remote moved. Investigate; force-push only on your human partner's explicit request.
Raw lines 212 to 225
Involves a person and wait :217

From obra/superpowers at 2ce8aa1, 2026-10-21. Skills read by DeepSeek V4.1 Flash on 2026-11-04. Summary and techniques by Claude Opus 5.5 on 2026-11-06.