Problem
When running gh pr merge --squash --delete-branch from within a git worktree (not the main worktree), the command creates a partial failure state:
- The GitHub API merge succeeds (PR is merged)
- The local
git checkout <base-branch> fails because the base branch is already checked out in the main worktree
Error message:
fatal: '<base>' is already used by worktree at '/path/to/main-worktree'
The result is a confusing state where:
- The PR is merged on GitHub
- Local cleanup (branch deletion) did not happen
- Re-running the command says "PR already merged" + "cannot delete branch used by worktree"
Expected Behavior
One of the following improvements would resolve this:
Option A: Add a --no-local / --remote-only flag to skip local git operations after merge, for users who prefer to handle local cleanup separately.
Option B: Detect when the base branch is checked out in another worktree and skip the local git checkout <base> step automatically (since it's not strictly necessary for cleanup).
Option C: When the local git operations fail after a successful API merge, emit a clearer message explaining that the PR was merged but local cleanup failed, and suggest the manual cleanup steps.
Current Workaround
Run from the main worktree directory (where the base branch is checked out) rather than from within the feature worktree. Or: remove the worktree first, then run gh pr merge.
Environment
gh version: latest
- Scenario: git worktree workflow (feature branch checked out in a separate worktree directory while
main is checked out in the primary worktree)
Problem
When running
gh pr merge --squash --delete-branchfrom within a git worktree (not the main worktree), the command creates a partial failure state:git checkout <base-branch>fails because the base branch is already checked out in the main worktreeError message:
The result is a confusing state where:
Expected Behavior
One of the following improvements would resolve this:
Option A: Add a
--no-local/--remote-onlyflag to skip local git operations after merge, for users who prefer to handle local cleanup separately.Option B: Detect when the base branch is checked out in another worktree and skip the local
git checkout <base>step automatically (since it's not strictly necessary for cleanup).Option C: When the local git operations fail after a successful API merge, emit a clearer message explaining that the PR was merged but local cleanup failed, and suggest the manual cleanup steps.
Current Workaround
Run from the main worktree directory (where the base branch is checked out) rather than from within the feature worktree. Or: remove the worktree first, then run
gh pr merge.Environment
ghversion: latestmainis checked out in the primary worktree)