---
name: finishing-a-development-branch
description: Use when dev work is complete and tests pass: run the suite, offer merge, PR, or keep-as-is, execute the choice, and clean up safely.
---
# Finish a Dev Branch
## What this does
Verify tests, detect the git environment, present integration options, execute the user's choice, then clean up. Announce at start: "I'm using the finishing-a-development-branch skill to complete this work."
## When to use
Implementation is complete and you need to decide how to integrate the work.
## How to run it
1. **Verify tests.** Run the full suite (`npm test` / `cargo test` / `pytest` / `go test ./...`). If anything fails, report the failures and stop; the menu comes only after a green suite.
2. **Detect environment** and capture values before changing directory:
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)
Equal dirs = normal repo (3 options, no worktree cleanup). Different dirs + named branch = 3 options. Different dirs + detached HEAD = 2 options (no merge), workspace left in place.
3. **Determine base branch.** If not already known, ask: "This branch split from <your best guess> - is that correct?" Confirm before merging.
4. **Present exactly these options and wait for the answer:**
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 gets: 1. Push as new branch and create a Pull Request, 2. Keep as-is.
5. **Execute the choice.**
- Option 1: `cd` to the main repo root, `git checkout <base-branch>`, `git pull`, `git merge <feature-branch>`, run tests on the merged result. If they fail, stop and leave worktree and branch in place. If green, clean up the worktree (step 6), then `git branch -d <feature-branch>`.
- Option 2: `git push -u origin <feature-branch>` (from detached HEAD: `git push origin HEAD:refs/heads/<new-branch>`), create the PR against the base with the forge's CLI or URL, following repo PR conventions, and report the URL. Keep the worktree.
- Option 3: report "Keeping branch <name>. Worktree preserved at <path>."
- Discard: only if the user explicitly asks. Show the branch, commits and worktree to be deleted, require the typed word `discard`, then clean up and `git branch -D`.
6. **Cleanup** (Option 1 and confirmed discards only): normal repo, nothing to do. If the worktree is under `.worktrees/` or `worktrees/`, run `git worktree remove "$WORKTREE_PATH"` then `git worktree prune`. If removal is refused, never use `--force` on your own: list the files (`git -C "$WORKTREE_PATH" status --porcelain -uall`) and ask whether to commit them, move them, or delete them. Any other worktree belongs to the host; leave it.
Guardrails: run the suite on the tree you will integrate; never assume merge intent; never force-push unless explicitly asked; a failing merged result stops everything.
## Output
Test results, the chosen option carried out, the PR URL if created, and cleanup status.
## Credit
Based on public content by obra, packaged by Orbit.