Skip to content

fix(worktree): base new worktrees on origin/<branch> by default#37

Merged
aletc1 merged 1 commit intodevfrom
claude/gracious-mendeleev-9abb2f
Apr 24, 2026
Merged

fix(worktree): base new worktrees on origin/<branch> by default#37
aletc1 merged 1 commit intodevfrom
claude/gracious-mendeleev-9abb2f

Conversation

@aletc1
Copy link
Copy Markdown
Owner

@aletc1 aletc1 commented Apr 24, 2026

Summary

  • Auto-select the remote variant of the default branch when both local and remote exist — new worktrees start from a fresh origin/<branch> instead of a potentially stale local ref.
  • Remove the branchType !== "local" gate on the pre-create fetch, so git fetch origin <baseBranch> runs whenever an origin remote is configured.

Why

#35 added a pre-create fetch, but gated it on branchType !== "local". The new-chat UI preferred the local variant of the default branch when both existed (the common case: local main tracking origin/main), so branchType was always "local" and the fetch never ran. Worktrees inherited whatever stale state the user happened to have locally — the original bug this series was supposed to fix.

User's local branch is left untouched (no fast-forward). Explicit branch selection from the dropdown is still honored.

Test plan

  • Repo with local main behind origin/main: new workspace → worktree HEAD includes commits only on origin/main
  • Repo without an origin remote: worktree creation still succeeds
  • Explicitly pick the local variant of a branch from the dropdown → worktree based on local ref (user's choice honored)
  • Local-only feature branch (no remote counterpart): creation succeeds; silent fetch-failed warning in logs is expected

Follow-up to #35. The pre-create fetch was gated on
`branchType !== "local"`, but the new-chat UI auto-selected the local
variant of the default branch whenever both local and remote existed —
so in the common case (local `main` tracking `origin/main`) the fetch
never ran and worktrees inherited whatever stale state the user had
locally.

- Auto-select prefers the remote variant of the default branch, so the
  worktree starts from a fresh `origin/<branch>`.
- `git fetch origin <baseBranch>` now runs whenever origin exists,
  regardless of branch type. Failures remain best-effort.

User's local branch is left untouched. Explicit local branch selection
is still honored.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@aletc1 aletc1 merged commit e9eed49 into dev Apr 24, 2026
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