Skip to content

fix: use explicit refspec for push in worktrees with slashed branch names#1684

Merged
juliusmarminge merged 2 commits intopingdotgg:mainfrom
D3OXY:fix/worktree-push-slashed-branches
Apr 2, 2026
Merged

fix: use explicit refspec for push in worktrees with slashed branch names#1684
juliusmarminge merged 2 commits intopingdotgg:mainfrom
D3OXY:fix/worktree-push-slashed-branches

Conversation

@D3OXY
Copy link
Copy Markdown
Contributor

@D3OXY D3OXY commented Apr 2, 2026

Summary

  • Fixes git push -u <remote> <branch> failing in git worktrees when the branch name contains a slash (e.g. t3code/my-feature)

Problem

When a worktree branch has no upstream tracking configured, pushCurrentBranch takes the pushWithUpstream path and runs:

git push -u origin t3code/my-feature

This fails with:

fatal: t3code/my-feature cannot be resolved to branch

The branch ref exists — git rev-parse --verify t3code/my-feature and git branch --show-current both work correctly. But git push with a bare branch name containing slashes cannot resolve it from a linked worktree's context. This is a known git limitation with worktrees and hierarchical branch names.

Reproduction

  1. Create a worktree with a slashed branch: git worktree add -b t3code/abc12345 /tmp/wt main
  2. Make a commit in the worktree
  3. Try to push: cd /tmp/wt && git push -u origin t3code/abc12345
  4. Observe: fatal: t3code/abc12345 cannot be resolved to branch

This affects the default worktree flow since t3code/<hex> branches are created without upstream tracking, and after the branch rename to t3code/<descriptive-name>, the first push goes through this code path.

Fix

Use an explicit refspec instead of a bare branch name:

git push -u origin HEAD:refs/heads/t3code/my-feature

This is semantically equivalent but bypasses the resolution issue by using HEAD (always valid in any worktree) as the source and the fully qualified ref path as the target.

Only the pushWithUpstream path is affected — branches that already track a remote use git push without a branch argument, which works fine.

Test plan

  • Create a worktree from the branch picker in worktree mode
  • Let the agent rename the temp branch (e.g. t3code/abc12345t3code/fix-something)
  • Trigger a commit+push via the git actions button
  • Verify push succeeds and PR can be created

Note

Fix pushCurrentBranch to use explicit refspec for branches with slashes in their names

In GitCore.ts, the git push -u <remote> command now uses HEAD:refs/heads/<branch> instead of <branch> as the ref argument. Branch names containing slashes (e.g. feature/foo) were previously misinterpreted as remote paths by Git, causing the push to fail.

Macroscope summarized b4f93eb.


Note

Medium Risk
Changes the initial git push -u invocation for branches without an upstream, which could affect how new branches are published (though intended to be equivalent). Main risk is unexpected push behavior in edge cases due to altered refspec handling.

Overview
Fixes pushing a branch with no upstream from linked worktrees when the branch name contains slashes.

pushCurrentBranch now pushes using an explicit refspec (HEAD:refs/heads/<branch>) instead of passing the bare branch name to git push -u, avoiding Git’s branch-resolution issues in worktree contexts.

Written by Cursor Bugbot for commit b4f93eb. This will update automatically on new commits. Configure here.

…orktrees

When pushing a branch that has no upstream tracking configured (the
`pushWithUpstream` path in `pushCurrentBranch`), git is invoked as:

    git push -u <remote> <branch>

This fails in git worktrees when the branch name contains a slash
(e.g. `t3code/my-feature`), with:

    fatal: <branch> cannot be resolved to branch

This is a known git limitation — bare branch names with slashes
cannot be resolved from a linked worktree's context during push.
The branch ref exists (verified via `git rev-parse`), and
`git branch --show-current` reports it correctly, but `git push`
fails to resolve it.

The fix uses an explicit refspec instead:

    git push -u <remote> HEAD:refs/heads/<branch>

This is semantically equivalent but bypasses the branch name
resolution issue by using HEAD (always valid) as the source ref
and the fully qualified target ref path.

The `pushWithUpstream` code path is only reached when the branch
has no upstream configured — branches that already track a remote
use the simpler `git push` without a branch argument, which is
unaffected by this issue.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f57fb899-6ee7-47bb-b4a6-03c5e4aa12d8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added size:XS 0-9 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Apr 2, 2026
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp bot commented Apr 2, 2026

Approvability

Verdict: Approved

Simple one-line bug fix that uses the explicit git refspec format (HEAD:refs/heads/branch) instead of just the branch name, which is the standard fix for handling branches with slashes in worktree scenarios. The change follows a well-known git pattern with no side effects.

You can customize Macroscope's approvability policy. Learn more.

@juliusmarminge juliusmarminge merged commit d2822a8 into pingdotgg:main Apr 2, 2026
9 of 10 checks passed
@D3OXY D3OXY deleted the fix/worktree-push-slashed-branches branch April 5, 2026 05:55
gigq pushed a commit to gigq/t3code that referenced this pull request Apr 6, 2026
…ames (pingdotgg#1684)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
Chrono-byte pushed a commit to Chrono-byte/t3code that referenced this pull request Apr 7, 2026
…ames (pingdotgg#1684)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants