Skip to content

source-control:pull-request merge: --delete-branch fails from a worktree when the default branch is checked out elsewhere #5207

Closed

Description

@kyle-sexton

Problem

reference/merge.md §4.2 always runs gh pr merge <N> --squash --delete-branch. When run from a linked worktree whose repository has the default branch checked out in another worktree, gh completes the merge on GitHub, then tries to check out the default branch locally and fails:

failed to run git: fatal: 'main' is already used by worktree at '/home/kyle/repos/github.com/melodic-software/.github'

The command exits 1 even though the merge succeeded, so the agent has to confirm the merge with gh pr view before it can continue. §4.3's worktree path already expects the default branch to be unavailable locally ("checkout of the default branch — that's blocked in a worktree"), so §4.2 contradicts it.

Repro

  1. Keep main checked out in the primary checkout.
  2. From a linked worktree on a PR branch, run /source-control:pull-request merge.
  3. gh pr merge <N> --squash --delete-branch exits 1 with the error above; the PR shows MERGED.

Seen on melodic-software/.github#153, 2026-09-29, source-control 0.58.4.

Suggested fix

In a linked worktree, drop --delete-branch. Delete the remote branch with git push origin --delete <branch> unless the repo reports deleteBranchOnMerge: true, in which case GitHub deletes it already. §4.3 already deletes the local branch. The same flag appears in templates/checklist.md.

Activity

  1. added
    needs-triageNot yet classified. Floor until a type and one priority tier are set.
    on Sep 29, 2026
  2. kyle-sexton commented on Sep 29, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during triage.

    Agent Brief

    Type: Bug
    Summary: pull-request merge from a linked worktree deletes the remote branch without --delete-branch.

    Current behavior:
    merge passes --delete-branch, which tries to check out the default branch; that fails in a linked worktree when the default branch is checked out elsewhere. The merge reference already notes default checkout is blocked in a worktree.

    Desired behavior:
    In a linked worktree, merge omits --delete-branch and deletes the remote branch with git push origin --delete <branch> unless the repo's deleteBranchOnMerge is true. The PR checklist template matches.

    Acceptance criteria:

    • The merge reference and checklist template describe the worktree path.
  3. added
    priority: mediumReal value, no hard deadline; normal backlog flow.
    work-class: mechanicalDeterministic, trivially reversible maintenance: dependency bumps, lint/format, sync.
    agent-readyFully specified and briefed; eligible for autonomous pickup from the frontier.
    and removed
    needs-triageNot yet classified. Floor until a type and one priority tier are set.
    on Sep 29, 2026
  4. added theissue type on Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyFully specified and briefed; eligible for autonomous pickup from the frontier.priority: mediumReal value, no hard deadline; normal backlog flow.work-class: mechanicalDeterministic, trivially reversible maintenance: dependency bumps, lint/format, sync.

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions