Skip to content

Fix wt add failing when local branch exists without remote#12

Merged
bkildow merged 1 commit intomainfrom
fix/add-local-branch-check
Mar 24, 2026
Merged

Fix wt add failing when local branch exists without remote#12
bkildow merged 1 commit intomainfrom
fix/add-local-branch-check

Conversation

@bkildow
Copy link
Copy Markdown
Owner

@bkildow bkildow commented Mar 24, 2026

Summary

  • wt add <branch> failed with fatal: a branch named '<branch>' already exists when a local branch ref existed in the bare repo but had no remote tracking branch (e.g., worktree removed outside wt, or branch created directly with git branch)
  • Added HasLocalBranch method using git rev-parse --verify refs/heads/<branch> to the Git interface and Runner
  • Changed branch resolution order from remote → new to remote → local → new, so orphaned local branches use WorktreeAdd instead of WorktreeAddNew -b

Test plan

  • make dev passes (fmt, vet, tests, build)
  • All e2e tests pass
  • Dry-run test for HasLocalBranch added
  • Manual: create orphaned local branch in bare repo (git branch test-orphan), verify wt add test-orphan succeeds

When a local branch ref exists in the bare repo but has no remote
tracking branch (e.g., worktree removed outside wt, or branch created
directly with git branch), wt add would fail with "fatal: a branch
named '<branch>' already exists" because it fell through to
WorktreeAddNew which uses -b to create a new branch.

Add HasLocalBranch check using git rev-parse --verify refs/heads/<branch>
so the resolution order is: remote branch → local branch → new branch.
Both existing branch paths use WorktreeAdd (no -b flag).
@bkildow bkildow merged commit 6ee9f47 into main Mar 24, 2026
@bkildow bkildow deleted the fix/add-local-branch-check branch March 24, 2026 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant