[BUG] Worktree sets branch upstream to origin/dev, causing VS Code push to go to dev instead of feature branch

Resolved 💬 4 comments Opened Mar 19, 2026 by erezcor Closed May 24, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

When Claude Code creates a worktree, it branches from origin/dev (a remote-tracking branch) rather than the local dev branch. With the default branch.autoSetupMerge=true, this causes git to automatically set branch.<name>.merge=refs/heads/dev - making the feature branch track origin/dev as its upstream.

This is catastrophic for users with push.autoSetupRemote=true, because:

  1. Normally: user creates git checkout -b ASP-XXXX dev (from local dev) -> no upstream is set -> push.autoSetupRemote kicks in on first push -> creates origin/ASP-XXXX correctly
  2. With worktree: Claude Code branches from origin/dev (remote-tracking) -> upstream is set to origin/dev -> push.autoSetupRemote does NOT kick in (upstream already exists) -> push goes directly to dev

When the user clicks "Push" in VS Code, VS Code reads the tracking config and runs git push origin <branch>:dev, pushing directly to the main development branch instead of the feature branch.

What Should Happen?

The worktree branch should either:

  • Be created from the local branch (not the remote-tracking branch), so that branch.autoSetupMerge=true does not set upstream tracking
  • Or explicitly clear/unset the upstream tracking after branch creation (git branch --unset-upstream)
  • Or set the upstream to match the branch name (origin/<branch-name>)

Error Messages/Logs

Git config after worktree creation:

branch.ASP-1305.remote=origin
branch.ASP-1305.merge=refs/heads/dev       # <-- should NOT be set, or should be refs/heads/ASP-1305

VS Code push log showing the wrong target:

git push origin worktree-ASP-1305:dev
git push origin ASP-1305:dev

Both pushes went to dev, bypassing branch protection (user had admin bypass).

Steps to Reproduce

  1. Have push.autoSetupRemote=true in git config (common modern git setup)
  2. Be on a feature branch (e.g., ASP-1305) created from local dev
  3. Use Claude Code worktree feature (EnterWorktree)
  4. After exiting the worktree, check git config branch.<name>.merge - it will show refs/heads/dev
  5. Click "Push" in VS Code -> commits go directly to dev

Impact

Commits were pushed directly to the protected dev branch unintentionally. This bypassed the PR workflow and branch protection rules.

Related Issues

  • #33596 - opposite problem: worktree branches with no upstream (fails to push)
  • #30070 - worktree using wrong remote in multi-remote setups

Claude Model

Opus

Is this a regression?

Not sure

Claude Code Version

Latest

Platform

Anthropic API

Operating System

Windows 11

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗