Skip to content

fix(git): use configured push target for Push and Sync#323650

Draft
AbdelrahmanHafez wants to merge 5 commits into
microsoft:mainfrom
AbdelrahmanHafez:fix/git-sync-push-target
Draft

fix(git): use configured push target for Push and Sync#323650
AbdelrahmanHafez wants to merge 5 commits into
microsoft:mainfrom
AbdelrahmanHafez:fix/git-sync-push-target

Conversation

@AbdelrahmanHafez

@AbdelrahmanHafez AbdelrahmanHafez commented Jun 30, 2026

Copy link
Copy Markdown

Fixes #137686, fixes #182510, fixes #158644

The issue was that the Git extension was treating the upstream branch as the push target. For a local branch named feature that tracks upstream/main, VS Code would explicitly run the equivalent of:

git push upstream feature:main

That bypasses Git's normal push destination logic. In practice that means VS Code could ignore push.default=simple, push.default=current, remote.pushDefault, and triangular workflow config, and it could push a feature branch into main even though plain git push would either push somewhere else or refuse.

I've been personally burned by this multiple times where I had to revert PRs accidentally merged to main while working on git worktrees on other branches.

This PR:

  • stops constructing HEAD.name:HEAD.upstream.name for the regular Push command
  • keeps the Sync pull side explicit, since upstream is still the pull/rebase source
  • lets Git decide the push target for the push half of Sync by running push without an explicit remote/refspec
  • stops using the upstream remote's read-only state to decide whether Sync can push, because the configured push remote can be different from the upstream remote
  • updates the Sync confirmation and status tooltip copy so they no longer claim pushes go to the upstream branch
  • adds Git integration tests for push.default=current, remote.pushDefault, and a read-only upstream remote with a configured push remote

This does not change explicit push commands like Push To, Publish Branch, Push Tags, or commands where the user explicitly picked a remote/refspec. It only changes the default Push/Sync path to line up with what Git would do for git push.

I also verified the failure mode before the implementation: the new tests failed because VS Code pushed feature:main to the upstream remote. All tests fail for the right reasons, and pass after the changes.

Copilot AI review requested due to automatic review settings June 30, 2026 01:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the built-in Git extension’s default Push and Sync behavior to stop constructing an explicit remote refspec from the upstream branch, and instead delegate push-target selection to Git’s own configuration (push.default, remote.pushDefault, triangular workflow), while keeping the pull/rebase side of Sync explicitly tied to the upstream branch.

Changes:

  • Default Push and the push-half of Sync now run without an explicit remote/refspec so Git decides the destination.
  • Sync UI messaging (confirmation + tooltip) no longer claims pushes go to the upstream branch.
  • Adds Git integration tests covering push.default=current, remote.pushDefault, and “read-only upstream + configured push remote”.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
extensions/git/src/test/push.test.ts Adds integration tests validating Push/Sync respect Git’s configured push destination (including read-only upstream scenarios).
extensions/git/src/repository.ts Changes Push/Sync push execution to omit remote/refspec and updates Sync tooltip/label behavior accordingly.
extensions/git/src/commands.ts Updates Sync confirmation prompt copy and removes upstream-remote read-only gating for prompting.

Comment thread extensions/git/src/test/push.test.ts Outdated
Comment thread extensions/git/src/repository.ts
Comment thread extensions/git/src/repository.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread extensions/git/src/commands.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread extensions/git/src/repository.ts Outdated
Comment thread extensions/git/src/commands.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

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

Labels

None yet

Projects

None yet

3 participants