Skip to content

Commit 99368b0

Browse files
fix: use origin/ ref when branching from default branch (#149)
resolve_default_branch returns a bare branch name (e.g. "main") which points to the local branch. After git fetch, origin/main is up to date but the local main may be stale — causing new worktrees to start from an old commit. The resolved_ref logic in create_worktree compounds this: it tries git rev-parse "main^{commit}" first, which succeeds with the stale local SHA, so the origin/ fallback never runs. Prefix with origin/ so new branches always start from the latest remote.
1 parent 4a4e21b commit 99368b0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/commands/create.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ _create_resolve_from_ref() {
7373
from_ref=$(get_current_branch)
7474
if [ -z "$from_ref" ] || [ "$from_ref" = "HEAD" ]; then
7575
log_warn "Currently in detached HEAD state - falling back to default branch"
76-
from_ref=$(resolve_default_branch "$repo_root")
76+
from_ref="origin/$(resolve_default_branch "$repo_root")"
7777
else
7878
log_info "Creating from current branch: $from_ref"
7979
fi
8080
else
81-
from_ref=$(resolve_default_branch "$repo_root")
81+
from_ref="origin/$(resolve_default_branch "$repo_root")"
8282
fi
8383
fi
8484

0 commit comments

Comments
 (0)