Skip to content

fix(desktop): prevent implicit upstream tracking when creating worktrees#491

Merged
saddlepaddle merged 1 commit intosuperset-sh:mainfrom
CalebBarnes:fix/create-new-branch-without-remote-upstream-set
Dec 23, 2025
Merged

fix(desktop): prevent implicit upstream tracking when creating worktrees#491
saddlepaddle merged 1 commit intosuperset-sh:mainfrom
CalebBarnes:fix/create-new-branch-without-remote-upstream-set

Conversation

@CalebBarnes
Copy link
Copy Markdown
Contributor

@CalebBarnes CalebBarnes commented Dec 23, 2025

Description

When creating a new branch from a remote branch (e.g., origin/main), Git implicitly sets upstream tracking to that remote branch. This causes git pull to pull from the base branch instead of the new branch's remote.

By appending ^{commit} to the startPoint, Git treats it as a commit object rather than a branch ref, preventing implicit upstream tracking. The new branch starts with no upstream, which matches the 'new branch' intent and allows push.autoSetupRemote to work correctly on first push.

Related Issues

Type of Change

  • Bug fix
  • New feature
  • Documentation
  • Refactor
  • Other (please describe):

Testing

Screenshots (if applicable)

Additional Notes

Summary by CodeRabbit

  • Bug Fixes
    • Fixed git worktree creation to prevent unintended upstream branch tracking when creating worktrees from remote references.

✏️ Tip: You can customize this high-level summary in your review settings.

When creating a new branch from a remote branch (e.g., origin/main),
Git implicitly sets upstream tracking to that remote branch. This causes
git pull to pull from the base branch instead of the new branch's remote.

By appending ^{commit} to the startPoint, Git treats it as a commit
object rather than a branch ref, preventing implicit upstream tracking.
The new branch starts with no upstream, which matches the 'new branch'
intent and allows push.autoSetupRemote to work correctly on first push.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 23, 2025

Walkthrough

The createWorktree function in the Git utility module is updated to transform the startPoint argument before passing it to the git worktree add command. The startPoint is now referenced as ${startPoint}^{commit} to force Git to treat it as a commit object rather than a branch reference, preventing implicit upstream tracking behavior.

Changes

Cohort / File(s) Summary
Git Worktree Creation
apps/desktop/src/lib/trpc/routers/workspaces/utils/git.ts
Modified createWorktree function to transform startPoint argument to ${startPoint}^{commit} syntax when passed to git worktree add command, preventing implicit upstream tracking from remote branches

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: preventing implicit upstream tracking when creating worktrees, which directly matches the core modification in the code.
Description check ✅ Passed The description provides a clear explanation of the problem and solution but has incomplete template sections: Related Issues, Testing, Screenshots, and Type of Change checkboxes are not filled out.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between caf5def and ce5183f.

📒 Files selected for processing (1)
  • apps/desktop/src/lib/trpc/routers/workspaces/utils/git.ts
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Avoid using any type in TypeScript - maintain type safety unless absolutely necessary

Files:

  • apps/desktop/src/lib/trpc/routers/workspaces/utils/git.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Run Biome for formatting, linting, import organization, and safe fixes at the root level using bun run lint:fix

Files:

  • apps/desktop/src/lib/trpc/routers/workspaces/utils/git.ts
apps/desktop/**/*.{ts,tsx}

📄 CodeRabbit inference engine (apps/desktop/AGENTS.md)

apps/desktop/**/*.{ts,tsx}: For Electron interprocess communication, ALWAYS use tRPC as defined in src/lib/trpc
Use alias as defined in tsconfig.json when possible
Prefer zustand for state management if it makes sense. Do not use effect unless absolutely necessary.
For tRPC subscriptions with trpc-electron, ALWAYS use the observable pattern from @trpc/server/observable instead of async generators, as the library explicitly checks isObservable(result) and throws an error otherwise

Files:

  • apps/desktop/src/lib/trpc/routers/workspaces/utils/git.ts
🔇 Additional comments (1)
apps/desktop/src/lib/trpc/routers/workspaces/utils/git.ts (1)

141-144: LGTM! Correctly prevents implicit upstream tracking.

The use of ^{commit} to force Git to treat the startPoint as a commit object rather than a branch reference is the correct approach. This prevents the new branch from automatically tracking the remote branch (e.g., origin/main), allowing push.autoSetupRemote to establish the correct upstream on first push.

The comment clearly documents the intent, and the syntax is standard Git that works with branch references, commit SHAs, and tags. The comprehensive error handling already in place will appropriately surface any issues if an invalid reference is provided.


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.

@saddlepaddle
Copy link
Copy Markdown
Collaborator

Nice catch! Thanks for the PR @CalebBarnes 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants