Skip to content

fix: checkout existing branch no longer results in detached HEAD#58

Merged
avihut merged 3 commits intodevelopfrom
daft-47/detached-head-checkout
Jan 22, 2026
Merged

fix: checkout existing branch no longer results in detached HEAD#58
avihut merged 3 commits intodevelopfrom
daft-47/detached-head-checkout

Conversation

@avihut
Copy link
Owner

@avihut avihut commented Jan 22, 2026

Summary

  • Fixed git-worktree-checkout checking out branches in detached HEAD mode instead of properly on the branch
  • Fixed git-worktree-clone not setting up fetch refspec, which prevented upstream tracking from working
  • Fixed git-worktree-clone not setting upstream tracking for the default branch after clone

Root Causes

  1. Detached HEAD: The checkout command was using origin/branch as the checkout ref when a remote branch existed, which Git treats as a commit-ish rather than a branch name
  2. Missing refspec: git clone --bare doesn't set up remote.origin.fetch, so upstream tracking commands fail
  3. Missing upstream: After bare clone, only local refs exist (not refs/remotes/origin/*), so upstream tracking couldn't be set without fetching first

Changes

  • checkout.rs: Check if local branch exists first; use it directly or create from remote with proper tracking
  • clone.rs: Set up fetch refspec after bare clone; fetch and set upstream after creating worktree
  • git.rs: Added config_set() and setup_fetch_refspec() helper methods

Test plan

  • All 21 checkout integration tests pass
  • All 11 clone integration tests pass
  • Manual verification: git-worktree-checkout master no longer results in detached HEAD
  • Manual verification: git branch -vv shows proper upstream tracking after both clone and checkout

Fixes #47

🤖 Generated with Claude Code

@avihut avihut self-assigned this Jan 22, 2026
@avihut avihut added the enhancement New feature or request label Jan 22, 2026
@avihut avihut added this to the v1.0.0 milestone Jan 22, 2026
@avihut avihut linked an issue Jan 22, 2026 that may be closed by this pull request
@avihut avihut merged commit 892d01d into develop Jan 22, 2026
3 checks passed
@avihut avihut deleted the daft-47/detached-head-checkout branch January 22, 2026 19:41
avihut added a commit that referenced this pull request Jan 24, 2026
* fix: checking out existing branch in worktree is no more detached head

* fix: worktree-clone now properly sets remote tracking

By setting the refspect properly

* fix: master tracks origin properly on clone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Checking out master worktree checks it out in detached head mode

1 participant