[BUG] Worktree sets branch upstream to origin/dev, causing VS Code push to go to dev instead of feature branch
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:
- Normally: user creates
git checkout -b ASP-XXXX dev(from localdev) -> no upstream is set ->push.autoSetupRemotekicks in on first push -> createsorigin/ASP-XXXXcorrectly - With worktree: Claude Code branches from
origin/dev(remote-tracking) -> upstream is set toorigin/dev->push.autoSetupRemotedoes NOT kick in (upstream already exists) -> push goes directly todev
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=truedoes 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
- Have
push.autoSetupRemote=truein git config (common modern git setup) - Be on a feature branch (e.g.,
ASP-1305) created from localdev - Use Claude Code worktree feature (EnterWorktree)
- After exiting the worktree, check
git config branch.<name>.merge- it will showrefs/heads/dev - 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
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗