Skip to content

wt should reuse matching local branches and track matching remote branches when creating a worktree #5

@ukanga

Description

@ukanga

Problem

When creating a worktree from a name that already exists as a branch, wt should not always create a fresh branch from the default base.

Expected behavior:

  • If name matches a local branch, check out that branch in the new worktree.
  • If name matches a remote-tracking branch, create the worktree from that remote branch and track it.
  • If multiple remote branches match, prompt the user to choose which remote to use.

Repro

  1. Have a repo with origin/feature/remote-worktree-match.
  2. Run wt session add feature/remote-worktree-match or wt new feature/remote-worktree-match.
  3. Observe whether wt uses the matching branch/ref or falls back to the base branch.

Expected

wt should create the worktree on feature/remote-worktree-match when it exists locally, or on the matching remote branch when only origin/feature/remote-worktree-match exists.

Actual

Before the fix, wt could create a new branch from the base branch instead of using the existing branch/ref.

Acceptance Criteria

  • Local branch match reuses the existing branch.
  • Remote branch match checks out a tracked branch from that remote ref.
  • Ambiguous remote matches prompt the user to choose.
  • Tests cover local, remote, and ambiguous remote cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions