Skip to content

Fast-forward existing behind-only branches during PR checkout - #8903

Merged
Alex Ross (alexr00) merged 3 commits into
mainfrom
copilot/fix-checkout-pull-request-issue
Aug 27, 2026
Merged

Fast-forward existing behind-only branches during PR checkout#8903
Alex Ross (alexr00) merged 3 commits into
mainfrom
copilot/fix-checkout-pull-request-issue

Conversation

Copilot AI commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Checkout Pull Request created a pr/<author>/<number> branch whenever the local and remote SHAs differed—even when the existing local branch was only behind. This left the expected branch stale and associated the PR with the generated branch.

  • Checkout behavior
    • Reuse the local branch when it is behind-only and tracks the PR’s remote head.
    • Check out and pull that branch instead of creating a generated PR branch.
    • Preserve the existing unique-branch behavior for divergent or unrelated branches.
const canFastForward = branch.behind > 0
  && branch.ahead === 0
  && branch.upstream?.remote === remoteName
  && branch.upstream?.name === originalBranchName;
  • Regression coverage
    • Verify a behind-only branch is checked out, pulled, and associated with the PR without creating pr/<author>/<number>.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue with checkout pull request creating new branch Fast-forward existing behind-only branches during PR checkout Aug 26, 2026
@alexr00
Alex Ross (alexr00) marked this pull request as ready for review August 27, 2026 11:55
Copilot AI lite review requested due to automatic review settings August 27, 2026 11:55

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 “Checkout Pull Request” flow to reuse an existing local PR head branch when it’s only behind the remote (safe fast-forward), instead of always creating a generated pr/<author>/<number> branch whenever SHAs differ. It also adds regression tests to ensure behind-only branches are pulled and associated with the PR without generating a new branch.

Changes:

  • Reuse and fast-forward an existing behind-only local branch that tracks the PR head, rather than creating pr/<author>/<number>.
  • Add tests covering: behind-only branch checkout + pull, behind-only already-checked-out pull, and a worktree scenario where a unique branch is used.
Show a summary per file
File Description
src/github/pullRequestGitHelper.ts Adds “behind-only + tracking” detection to allow fast-forwarding the existing branch during PR checkout.
src/test/github/pullRequestGitHelper.test.ts Adds regression tests validating the new checkout/fast-forward behavior and worktree handling.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread src/github/pullRequestGitHelper.ts
@alexr00
Alex Ross (alexr00) merged commit 2464fd6 into main Aug 27, 2026
7 checks passed
@alexr00
Alex Ross (alexr00) deleted the copilot/fix-checkout-pull-request-issue branch August 27, 2026 13:19
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.

"Checkout Pull Request" creates a pr/<author>/<number> branch when the local branch is only behind the remote

4 participants