Skip to content

Follow-up fix fails with "a branch named … already exists" when creating the worktree #3687

Closed

Description

@integry

Problem

On #3644 a follow-up fix failed four times in a row at worktree creation with git's "a branch named … already exists" (#3680 item 7). A leftover local branch from an earlier run of the same PR blocks every later run until someone cleans up by hand.

Expected / acceptance criteria

  • Creating the worktree for a follow-up on an existing PR branch succeeds when a local branch of that name already exists: the worker reuses it after resetting it to the fetched remote head, or removes the stale branch/worktree registration first (including git worktree prune for a registration whose directory is gone).
  • Work is never discarded silently: if the stale local branch has commits that are not on the remote PR branch, the run fails with a clear message naming the branch instead of deleting them.
  • Tests with a real temporary git repository for: stale branch equal to remote, stale branch behind remote, stale branch with unpushed commits, stale worktree registration.

Implementation

Look at the worktree creation path used for PR follow-ups in packages/core/src/git/ (worktree manager). Replace the unconditional git worktree add -b with a path that handles an existing branch as described. Run git-backed tests without SSH_ASKPASS.

Activity

  1. propr-dev commented on Nov 18, 2026

    @propr-dev
    Contributor

    🤖 AI processing has started for this issue using claude agent with claude-opus-5-5 model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Agent: claude
    • Model: claude-opus-5-5
    • Branch: 3687/claude-opus-5-5-follow-up-fix-fails-with--20261118-1159-u20
    • Base Branch: 3686-epic-0-9-g6i
    • Worktree: issue-3687-20261118-1159-claude-opus-5-5-u20

    🔍 Track Task Execution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions