Problem
The finishing skill's Option 1 (Merge Locally) has two cleanup bugs when running from inside a worktree — the expected context after worktree-based execution.
Bug 1: Branch deletion before worktree removal
After merging, the skill runs git branch -d <feature-branch> while the worktree still has that branch checked out. Git refuses:
error: cannot delete branch 'feature-branch' used by worktree at '/path/to/.worktrees/...'
The fix is to remove the worktree first, then delete the branch. The current order in the skill (Step 4 then Step 5) is reversed.
Bug 2: False "discard work" warning on already-merged commits
When removing the worktree after a successful merge, the worktree exit tool warns about discarding commits:
Worktree has 4 commits on feature-branch. Removing will discard this work permanently.
These commits were already fast-forward merged to the base branch — they are not at risk. The safety check should verify whether the branch's commits are reachable from the base branch before warning.
Reproduction
- Use
using-git-worktrees to create a worktree
- Make commits on the feature branch
- Invoke
finishing-a-development-branch, choose Option 1
- Observe: branch deletion fails, then worktree removal warns about already-merged commits
Suggested Fix
- Swap the order: remove worktree (Step 5) before deleting branch (end of Step 4)
- Before warning about discarding commits, check
git merge-base --is-ancestor <feature-branch> <base-branch> — if true, the commits are already merged and removal is safe
Context
Found during manual testing of #997. These are pre-existing bugs, not introduced by that PR. Related: #167 (checkout failure from worktree, same Option 1 flow).
Problem
The finishing skill's Option 1 (Merge Locally) has two cleanup bugs when running from inside a worktree — the expected context after worktree-based execution.
Bug 1: Branch deletion before worktree removal
After merging, the skill runs
git branch -d <feature-branch>while the worktree still has that branch checked out. Git refuses:The fix is to remove the worktree first, then delete the branch. The current order in the skill (Step 4 then Step 5) is reversed.
Bug 2: False "discard work" warning on already-merged commits
When removing the worktree after a successful merge, the worktree exit tool warns about discarding commits:
These commits were already fast-forward merged to the base branch — they are not at risk. The safety check should verify whether the branch's commits are reachable from the base branch before warning.
Reproduction
using-git-worktreesto create a worktreefinishing-a-development-branch, choose Option 1Suggested Fix
git merge-base --is-ancestor <feature-branch> <base-branch>— if true, the commits are already merged and removal is safeContext
Found during manual testing of #997. These are pre-existing bugs, not introduced by that PR. Related: #167 (checkout failure from worktree, same Option 1 flow).