Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/main/lib/git/worktree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -971,9 +971,10 @@ export async function createWorktreeForChat(
const baseBranch = selectedBaseBranch || await getDefaultBranch(projectPath);

// Best-effort: refresh origin/<baseBranch> so the worktree is based on the
// latest remote state. Skipped for local-type branches (user opted into a
// local ref) and when no origin remote exists. Never blocks creation.
if (branchType !== "local" && (await hasOriginRemote(projectPath))) {
// latest remote state. Skipped only when there is no origin remote. Never
// blocks creation — failures (including local-only branches with no matching
// remote ref) are logged and swallowed.
if (await hasOriginRemote(projectPath)) {
try {
await withGitLock(projectPath, async () => {
const netGit = createGitForNetwork(projectPath);
Expand Down
10 changes: 6 additions & 4 deletions src/renderer/features/agents/main/new-chat-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -985,12 +985,14 @@ export function NewChatForm({
validatedProject?.id &&
!selectedBranch
) {
// Find the default branch in the branches list to get its type
// Prefer local over remote if both exist
// Find the default branch in the branches list to get its type.
// Prefer remote over local so new worktrees are based on the freshest
// origin state. Only fall back to local if the default branch has no
// remote counterpart.
const defaultBranchObj = branches.find(
(b) => b.name === branchesQuery.data.defaultBranch && b.isDefault && b.type === "local",
) || branches.find(
(b) => b.name === branchesQuery.data.defaultBranch && b.isDefault && b.type === "remote",
) || branches.find(
(b) => b.name === branchesQuery.data.defaultBranch && b.isDefault && b.type === "local",
)
// Fallback to "local" if branch not found in list (shouldn't happen but prevents empty selector)
const branchType = defaultBranchObj?.type || "local"
Expand Down