finishing-a-development-branch
Structured "done coding, now what?" workflow: verify tests pass, detect the repository environment (normal repo vs worktree, named branch vs detached HEAD), present exactly the right merge / PR / keep / discard options, and execute the chosen path including safe worktree cleanup. Use when implementation is complete and the branch needs to be integrated, published, or abandoned.
What this skill does
# Finishing a Development Branch Guide completion of development work by presenting clear options and handling the chosen workflow end-to-end. **Core principle:** Verify tests → Detect environment → Present options → Execute choice → Clean up. ## The Process ### Step 1: Verify Tests Before presenting any options, run the project's test suite: ```bash # Use whichever test runner the project uses npm test / bun test / cargo test / pytest / go test ./... ``` If tests fail: ``` Tests failing (<N> failures). Must fix before completing: [show failures] Cannot proceed with merge/PR until tests pass. ``` Stop. Do not continue to Step 2 while tests are red. If tests pass, continue to Step 2. ### Step 2: Detect Environment Determine workspace state before presenting options: ```bash 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) ``` | State | Menu | Cleanup | |-------|------|---------| | `GIT_DIR == GIT_COMMON` (normal repo) | 4-option menu | No worktree to clean up | | `GIT_DIR != GIT_COMMON`, named branch | 4-option menu | Provenance-based (see Step 6) | | `GIT_DIR != GIT_COMMON`, detached HEAD | 3-option menu (no local merge) | Externally managed — do not remove | ### Step 3: Determine Base Branch ```bash git merge-base HEAD main 2>/dev/null || git merge-base HEAD master 2>/dev/null ``` If neither resolves, ask the user: "This branch appears to split from `main` — is that correct?" ### Step 4: Present Options **Normal repo and named-branch worktree — exactly 4 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 (handle it later) 4. Discard this work Which option? ``` **Detached HEAD — exactly 3 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 (handle it later) 3. Discard this work Which option? ``` Do not add explanation text to the menu — keep it concise. ### Step 5: Execute Choice #### Option 1: Merge Locally ```bash # Resolve main repo root first (safe when running inside a worktree) MAIN_ROOT=$(git -C "$(git rev-parse --git-common-dir)/.." rev-parse --show-toplevel) cd "$MAIN_ROOT" git checkout <base-branch> git pull git merge <feature-branch> ``` Run the test suite again on the merged result. Only after tests pass on the merge: run Step 6 to clean up the worktree, then delete the branch: ```bash git branch -d <feature-branch> ``` #### Option 2: Push and Create PR ```bash git push -u origin <feature-branch> gh pr create --title "<descriptive title>" --body "$(cat <<'EOF' ## Summary - <what changed, 2-3 bullets> ## Test Plan - [ ] <verification steps> EOF )" ``` Do **not** clean up the worktree — the user needs it alive to iterate on PR feedback. #### Option 3: Keep As-Is Report: "Keeping branch `<name>`. Worktree preserved at `<path>`." Do not clean up the worktree. #### Option 4: Discard Require typed confirmation before destroying anything: ``` This will permanently delete: - Branch <name> - All commits: <commit list> - Worktree at <path> (if applicable) Type 'discard' to confirm. ``` Wait for the exact word. If confirmed: ```bash MAIN_ROOT=$(git -C "$(git rev-parse --git-common-dir)/.." rev-parse --show-toplevel) cd "$MAIN_ROOT" ``` Run Step 6 to clean up the worktree, then force-delete the branch: ```bash git branch -D <feature-branch> ``` ### Step 6: Cleanup Workspace This step runs **only for Options 1 and 4**. Options 2 and 3 always preserve the worktree. ```bash 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) WORKTREE_PATH=$(git rev-parse --show-toplevel) ``` **If `GIT_DIR == GIT_COMMON`:** This is a normal repo checkout. No worktree to clean up. Done. **If the worktree path is under `.worktrees/` or `worktrees/` relative to the main repo root:** The current workflow created this worktree — it is safe to remove it. ```bash MAIN_ROOT=$(git -C "$(git rev-parse --git-common-dir)/.." rev-parse --show-toplevel) cd "$MAIN_ROOT" git worktree remove "$WORKTREE_PATH" git worktree prune # clean up any stale registrations ``` **Otherwise:** The host environment owns this workspace. Do **not** remove it. Leave the workspace in place and report the path to the user. ## Quick Reference | Option | Merge | Push | Keep Worktree | Delete Branch | |--------|-------|------|---------------|---------------| | 1. Merge locally | yes | — | — | yes (safe `-d`) | | 2. Create PR | — | yes | yes | — | | 3. Keep as-is | — | — | yes | — | | 4. Discard | — | — | — | yes (force `-D`) | ## Common Mistakes **Skipping test verification** - Problem: Broken code gets merged or published as a PR. - Fix: Always verify tests before offering options. **Open-ended questions instead of the menu** - Problem: "What should I do next?" is ambiguous and stalls the workflow. - Fix: Present exactly 4 structured options (or 3 for detached HEAD). **Cleaning up the worktree for Option 2** - Problem: The user needs the worktree alive to iterate on PR feedback. - Fix: Only clean up for Options 1 and 4. **Deleting the branch before removing the worktree** - Problem: `git branch -d` fails because the worktree still references it. - Fix: Remove the worktree first, then delete the branch. **Running `git worktree remove` from inside the worktree** - Problem: The command fails or silently does nothing. - Fix: Always `cd` to the main repo root before calling `git worktree remove`. **Cleaning up externally-managed worktrees** - Problem: Removing a workspace the host environment created causes phantom state. - Fix: Only clean up worktrees under `.worktrees/` or `worktrees/` paths that the current workflow owns. If provenance is unclear, leave it. **No confirmation for discard** - Problem: Work is accidentally destroyed. - Fix: Require the exact word `discard` typed by the user before proceeding. ## Iron Rules Never: - Proceed with failing tests. - Merge without re-verifying tests on the merged result. - Delete work without explicit typed confirmation. - Force-push without an explicit request from the user. - Remove a worktree before confirming the merge succeeded. - Clean up worktrees whose provenance is unknown or externally managed. - Run `git worktree remove` from inside the worktree being removed. Always: - Verify tests before offering options. - Detect environment before presenting the menu. - Present exactly 4 options (or 3 for detached HEAD) — no more, no less. - Get typed `discard` confirmation for Option 4. - Clean up the worktree for Options 1 and 4 only. - `cd` to the main repo root before any worktree removal. - Run `git worktree prune` after removal.
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.