{
  "name": "finishing-a-development-branch",
  "family": "code discipline",
  "description": "Use when implementation is complete, all tests pass, and you need to decide how to integrate the work",
  "body": "\n# Finishing a Development Branch\n\n## Overview\n\n**Core principle:** Verify tests → Detect environment → Present options → Execute choice → Clean up.\n\n**Announce at start:** \"I'm using the finishing-a-development-branch skill to complete this work.\"\n\n## Step 1: Verify Tests\n\nRun the project's full test suite (`npm test` / `cargo test` / `pytest` / `go test ./...`).\n\n**If tests fail**, report the failures and stop — the menu comes after a green suite:\n\n```\nTests failing (<N> failures). Must fix before completing:\n\n[Show failures]\n```\n\n**If tests pass:** continue to Step 2.\n\n## Step 2: Detect Environment\n\n```bash\nGIT_DIR=$(cd \"$(git rev-parse --git-dir)\" 2>/dev/null && pwd -P)\nGIT_COMMON=$(cd \"$(git rev-parse --git-common-dir)\" 2>/dev/null && pwd -P)\n# Capture now, while still inside the workspace — Step 5 changes directory\n# before cleanup (Step 6) needs this value\nWORKTREE_PATH=$(git rev-parse --show-toplevel)\n```\n\nThis determines which menu to show and how cleanup works:\n\n| State | Menu | Cleanup |\n|-------|------|---------|\n| `GIT_DIR == GIT_COMMON` (normal repo) | Standard 3 options | No worktree to clean up |\n| `GIT_DIR != GIT_COMMON`, named branch | Standard 3 options | Provenance-based (see Step 6) |\n| `GIT_DIR != GIT_COMMON`, detached HEAD | Reduced 2 options (no merge) | Externally managed — leave in place |\n\n## Step 3: Determine Base Branch\n\nThe base branch is whatever this work forked from — usually named in the\nplan, the conversation, or the branch's upstream. If it is not already\nknown, ask: \"This branch split from <your best guess> - is that correct?\"\nConfirm before merging: merging into the wrong base is expensive to undo.\n\n## Step 4: Present Options\n\n**Normal repo and named-branch worktree — present exactly these 3 options:**\n\n```\nImplementation complete. What would you like to do?\n\n1. Merge back to <base-branch> locally\n2. Push and create a Pull Request\n3. Keep the branch as-is (I'll handle it later)\n\nWhich option?\n```\n\n**Detached HEAD — present exactly these 2 options:**\n\n```\nImplementation complete. You're on a detached HEAD (externally managed workspace).\n\n1. Push as new branch and create a Pull Request\n2. Keep as-is (I'll handle it later)\n\nWhich option?\n```\n\nPresent the menu exactly as written — concise, with every option coming\nfrom the list above. Discarding the work happens only in response to your\nhuman partner explicitly asking for it (see \"If your human partner asks to\ndiscard the work\" below). Wait for their answer; the integration decision\nis theirs.\n\n## Step 5: Execute Choice\n\n### Option 1: Merge Locally\n\n```bash\n# Get main repo root for CWD safety\nMAIN_ROOT=$(git -C \"$(git rev-parse --git-common-dir)/..\" rev-parse --show-toplevel)\ncd \"$MAIN_ROOT\"\n\n# Merge first — verify success before removing anything\ngit checkout <base-branch>\ngit pull\ngit merge <feature-branch>\n\n# Verify tests on merged result\n<test command>\n```\n\nIf tests fail on the merged result: stop, leave the worktree and branch in\nplace, and investigate — nothing has been pushed, so the merge is local\nand recoverable.\n\nOnce the merged result is green: clean up the worktree (Step 6), then\ndelete the branch:\n\n```bash\ngit branch -d <feature-branch>\n```\n\n### Option 2: Push and Create PR\n\n```bash\ngit push -u origin <feature-branch>\n# From a detached HEAD, name the new branch on the remote:\n# git push origin HEAD:refs/heads/<new-branch>\n```\n\nThen create the pull/merge request against <base-branch> with the forge's\ntooling — its CLI if one is available, or the creation URL most forges\nprint when you push — following the repo's PR template and conventions if\npresent, and report the URL to your human partner.\n\nKeep the worktree — your human partner iterates on PR feedback there.\n\n### Option 3: Keep As-Is\n\nReport: \"Keeping branch <name>. Worktree preserved at <path>.\"\n\n### If your human partner asks to discard the work\n\nThis path exists only as a response to an explicit request to throw the\nwork away. Confirm first:\n\n```\nThis will permanently delete:\n- Branch <name>\n- All commits: <commit-list>\n- Worktree at <path>\n\nType 'discard' to confirm.\n```\n\nWait for that exact confirmation. When it arrives:\n\n```bash\nMAIN_ROOT=$(git -C \"$(git rev-parse --git-common-dir)/..\" rev-parse --show-toplevel)\ncd \"$MAIN_ROOT\"\n```\n\nThen clean up the worktree (Step 6) and force-delete the branch:\n\n```bash\ngit branch -D <feature-branch>\n```\n\n## Step 6: Cleanup Workspace\n\n**Runs for Option 1 and confirmed discards.** Options 2 and 3 always\npreserve the worktree. Both callers have already changed directory to the\nmain repo root — worktree removal must run from outside the worktree —\nand use the `GIT_DIR`/`GIT_COMMON`/`WORKTREE_PATH` values captured in\nStep 2, from before that directory change.\n\n**If `GIT_DIR == GIT_COMMON`:** Normal repo, no worktree to clean up. Done.\n\n**If `WORKTREE_PATH` is under `.worktrees/` or `worktrees/`:** Superpowers\ncreated this worktree — we own cleanup:\n\n```bash\ngit worktree remove \"$WORKTREE_PATH\"\ngit worktree prune  # Self-healing: clean up any stale registrations\n```\n\n**Otherwise:** The host environment owns this workspace — leave it in\nplace. If your platform provides a workspace-exit tool, use it.\n\n## Quick Reference\n\n| Option | Merge | Push | Keep Worktree | Cleanup Branch |\n|--------|-------|------|---------------|----------------|\n| 1. Merge locally | yes | - | - | yes |\n| 2. Create PR | - | yes | yes | - |\n| 3. Keep as-is | - | - | yes | - |\n| Discard (explicit request only) | - | - | - | yes (force) |\n\n## Common Rationalizations\n\n| Excuse | Reality |\n|--------|---------|\n| \"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. |\n| \"They obviously want it merged\" | Integration is your human partner's decision. Present the menu and wait. |\n| \"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. |\n| \"'Yeah, get rid of it' counts as confirmation\" | Only the typed word `discard` authorizes deletion. |\n| \"The PR is up, so the worktree is clutter now\" | PR feedback gets fixed in that worktree. It stays until the work lands. |\n| \"This other worktree looks stale — I'll clean it too\" | Clean up only worktrees under `.worktrees/` or `worktrees/`. Everything else belongs to the host. |\n| \"The merged-result failure is probably flaky\" | A failing merged result stops everything. Branch and worktree stay put while you investigate. |\n| \"The base branch is obviously main\" | Confirm the fork point or ask. Merging into the wrong base is expensive to undo. |\n| \"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. |\n",
  "raw": "---\nname: finishing-a-development-branch\ndescription: Use when implementation is complete, all tests pass, and you need to decide how to integrate the work\n---\n\n# Finishing a Development Branch\n\n## Overview\n\n**Core principle:** Verify tests → Detect environment → Present options → Execute choice → Clean up.\n\n**Announce at start:** \"I'm using the finishing-a-development-branch skill to complete this work.\"\n\n## Step 1: Verify Tests\n\nRun the project's full test suite (`npm test` / `cargo test` / `pytest` / `go test ./...`).\n\n**If tests fail**, report the failures and stop — the menu comes after a green suite:\n\n```\nTests failing (<N> failures). Must fix before completing:\n\n[Show failures]\n```\n\n**If tests pass:** continue to Step 2.\n\n## Step 2: Detect Environment\n\n```bash\nGIT_DIR=$(cd \"$(git rev-parse --git-dir)\" 2>/dev/null && pwd -P)\nGIT_COMMON=$(cd \"$(git rev-parse --git-common-dir)\" 2>/dev/null && pwd -P)\n# Capture now, while still inside the workspace — Step 5 changes directory\n# before cleanup (Step 6) needs this value\nWORKTREE_PATH=$(git rev-parse --show-toplevel)\n```\n\nThis determines which menu to show and how cleanup works:\n\n| State | Menu | Cleanup |\n|-------|------|---------|\n| `GIT_DIR == GIT_COMMON` (normal repo) | Standard 3 options | No worktree to clean up |\n| `GIT_DIR != GIT_COMMON`, named branch | Standard 3 options | Provenance-based (see Step 6) |\n| `GIT_DIR != GIT_COMMON`, detached HEAD | Reduced 2 options (no merge) | Externally managed — leave in place |\n\n## Step 3: Determine Base Branch\n\nThe base branch is whatever this work forked from — usually named in the\nplan, the conversation, or the branch's upstream. If it is not already\nknown, ask: \"This branch split from <your best guess> - is that correct?\"\nConfirm before merging: merging into the wrong base is expensive to undo.\n\n## Step 4: Present Options\n\n**Normal repo and named-branch worktree — present exactly these 3 options:**\n\n```\nImplementation complete. What would you like to do?\n\n1. Merge back to <base-branch> locally\n2. Push and create a Pull Request\n3. Keep the branch as-is (I'll handle it later)\n\nWhich option?\n```\n\n**Detached HEAD — present exactly these 2 options:**\n\n```\nImplementation complete. You're on a detached HEAD (externally managed workspace).\n\n1. Push as new branch and create a Pull Request\n2. Keep as-is (I'll handle it later)\n\nWhich option?\n```\n\nPresent the menu exactly as written — concise, with every option coming\nfrom the list above. Discarding the work happens only in response to your\nhuman partner explicitly asking for it (see \"If your human partner asks to\ndiscard the work\" below). Wait for their answer; the integration decision\nis theirs.\n\n## Step 5: Execute Choice\n\n### Option 1: Merge Locally\n\n```bash\n# Get main repo root for CWD safety\nMAIN_ROOT=$(git -C \"$(git rev-parse --git-common-dir)/..\" rev-parse --show-toplevel)\ncd \"$MAIN_ROOT\"\n\n# Merge first — verify success before removing anything\ngit checkout <base-branch>\ngit pull\ngit merge <feature-branch>\n\n# Verify tests on merged result\n<test command>\n```\n\nIf tests fail on the merged result: stop, leave the worktree and branch in\nplace, and investigate — nothing has been pushed, so the merge is local\nand recoverable.\n\nOnce the merged result is green: clean up the worktree (Step 6), then\ndelete the branch:\n\n```bash\ngit branch -d <feature-branch>\n```\n\n### Option 2: Push and Create PR\n\n```bash\ngit push -u origin <feature-branch>\n# From a detached HEAD, name the new branch on the remote:\n# git push origin HEAD:refs/heads/<new-branch>\n```\n\nThen create the pull/merge request against <base-branch> with the forge's\ntooling — its CLI if one is available, or the creation URL most forges\nprint when you push — following the repo's PR template and conventions if\npresent, and report the URL to your human partner.\n\nKeep the worktree — your human partner iterates on PR feedback there.\n\n### Option 3: Keep As-Is\n\nReport: \"Keeping branch <name>. Worktree preserved at <path>.\"\n\n### If your human partner asks to discard the work\n\nThis path exists only as a response to an explicit request to throw the\nwork away. Confirm first:\n\n```\nThis will permanently delete:\n- Branch <name>\n- All commits: <commit-list>\n- Worktree at <path>\n\nType 'discard' to confirm.\n```\n\nWait for that exact confirmation. When it arrives:\n\n```bash\nMAIN_ROOT=$(git -C \"$(git rev-parse --git-common-dir)/..\" rev-parse --show-toplevel)\ncd \"$MAIN_ROOT\"\n```\n\nThen clean up the worktree (Step 6) and force-delete the branch:\n\n```bash\ngit branch -D <feature-branch>\n```\n\n## Step 6: Cleanup Workspace\n\n**Runs for Option 1 and confirmed discards.** Options 2 and 3 always\npreserve the worktree. Both callers have already changed directory to the\nmain repo root — worktree removal must run from outside the worktree —\nand use the `GIT_DIR`/`GIT_COMMON`/`WORKTREE_PATH` values captured in\nStep 2, from before that directory change.\n\n**If `GIT_DIR == GIT_COMMON`:** Normal repo, no worktree to clean up. Done.\n\n**If `WORKTREE_PATH` is under `.worktrees/` or `worktrees/`:** Superpowers\ncreated this worktree — we own cleanup:\n\n```bash\ngit worktree remove \"$WORKTREE_PATH\"\ngit worktree prune  # Self-healing: clean up any stale registrations\n```\n\n**Otherwise:** The host environment owns this workspace — leave it in\nplace. If your platform provides a workspace-exit tool, use it.\n\n## Quick Reference\n\n| Option | Merge | Push | Keep Worktree | Cleanup Branch |\n|--------|-------|------|---------------|----------------|\n| 1. Merge locally | yes | - | - | yes |\n| 2. Create PR | - | yes | yes | - |\n| 3. Keep as-is | - | - | yes | - |\n| Discard (explicit request only) | - | - | - | yes (force) |\n\n## Common Rationalizations\n\n| Excuse | Reality |\n|--------|---------|\n| \"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. |\n| \"They obviously want it merged\" | Integration is your human partner's decision. Present the menu and wait. |\n| \"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. |\n| \"'Yeah, get rid of it' counts as confirmation\" | Only the typed word `discard` authorizes deletion. |\n| \"The PR is up, so the worktree is clutter now\" | PR feedback gets fixed in that worktree. It stays until the work lands. |\n| \"This other worktree looks stale — I'll clean it too\" | Clean up only worktrees under `.worktrees/` or `worktrees/`. Everything else belongs to the host. |\n| \"The merged-result failure is probably flaky\" | A failing merged result stops everything. Branch and worktree stay put while you investigate. |\n| \"The base branch is obviously main\" | Confirm the fork point or ask. Merging into the wrong base is expensive to undo. |\n| \"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. |\n",
  "files": [
    {
      "path": "LICENSE",
      "bytes": 1070
    },
    {
      "path": "SKILL.md",
      "bytes": 7022
    }
  ],
  "has_license_file": true,
  "source": {
    "repo": "obra/superpowers",
    "url": "https://github.com/obra/superpowers",
    "license": "MIT"
  },
  "prevents": [
    {
      "date": "2026-07-22",
      "failure": "Completed work saved on a side line does not exist for the build until folded into the live line; stranded finished work re-alarmed for weeks."
    }
  ],
  "canonical_source": ".claude/skills/finishing-a-development-branch/SKILL.md",
  "sibling": ".agents/skills/finishing-a-development-branch/SKILL.md"
}