Skip to content

finishing-a-development-branch Option 1: cleanup sequence fails inside worktree #999

@csillag

Description

@csillag

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

  1. Use using-git-worktrees to create a worktree
  2. Make commits on the feature branch
  3. Invoke finishing-a-development-branch, choose Option 1
  4. 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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    skillsSkill system, development, and individual skillsworktreesGit worktree management

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions