Skip to content

**Open a pull request** preview compares against fork's default branch instead of parent's #23120

Closed

Description

@PtJade-Ceramic

The problem

When Desktop previews a pull request for a branch that was created from the parent repository's default branch (for example git switch -c topic upstream/main), the preview is computed against the fork's own default branch. The pull request that is actually created targets the parent repository's default branch. If the fork's default branch is behind upstream, the preview lists every upstream commit as if it belonged to the pull request, reports that the branch cannot be merged automatically, and shows unrelated file changes.

Release version

3.6.10 (x64)

Operating system

Windows 11 (10.0.26300)

Steps to reproduce the behavior

  1. Find someone else's repo maintained actively.
  2. Fork it and clone the fork. Leave the fork's main behind the parent's main. (Go to your fork's homepage on GitHub to check this.)
  3. Create a branch from the parent's default branch.
  4. Make sure you are on the branch just created and make changes.
  5. Commit amd push.
  6. Preview the PR. (You will see the PR also containing all commits behind the upstream.)
  7. Click Create pull request. (The GitHub page open contains only the one commit created in Step 5.)

Log files

No response

Screenshots

Image Image

Additional context

Root cause

public async _startPullRequest(repository: Repository) {
const { tip, defaultBranch } =
this.repositoryStateCache.get(repository).branchesState
if (tip.kind !== TipState.Valid) {
// Shouldn't even be able to get here if so - just a type check
return
}
const currentBranch = tip.branch
this._initializePullRequestPreview(repository, defaultBranch, currentBranch)
}

this._initializePullRequestPreview(repository, defaultBranch, currentBranch)

const pullRequestCommits = await gitStore.getCommitsBetweenBranches(
baseBranch,
currentBranch
)

getBranchMergeBaseChangedFiles(
repository,
baseBranch.name,
currentBranch.name,
commitsBetweenBranches[0]
)

public async _openCreatePullRequestInBrowser(
repository: Repository,
compareBranch: Branch,
baseBranch?: Branch
): Promise<void> {
const gitHubRepository = repository.gitHubRepository
if (!gitHubRepository) {
return
}
const { parent, owner, name, htmlURL } = gitHubRepository
const isForkContributingToParent =
isForkedRepositoryContributingToParent(repository)
const baseForkPreface =
isForkContributingToParent && parent !== null
? `${parent.owner.login}:${parent.name}:`
: ''
const encodedBaseBranch =
baseBranch !== undefined
? baseForkPreface +
encodeURIComponent(baseBranch.nameWithoutRemote) +
'...'
: ''
const compareForkPreface = isForkContributingToParent
? `${owner.login}:${name}:`
: ''
const encodedCompareBranch =
compareForkPreface +
encodeURIComponent(
compareBranch.upstreamWithoutRemote ?? compareBranch.nameWithoutRemote
)
const compareString = `${encodedBaseBranch}${encodedCompareBranch}`
const baseURL = `${htmlURL}/pull/new/${compareString}`
await this._openInBrowser(baseURL)
}

const baseForkPreface =
isForkContributingToParent && parent !== null
? `${parent.owner.login}:${parent.name}:`
: ''

this._defaultBranch = await findDefaultBranch(
this.repository,
this.allBranches,
this.defaultRemote?.name
)

const upstreamDefaultBranch =

public async getCommitsBetweenBranches(

export function revRange(from: string, to: string) {
return `${from}..${to}`
}

export async function getBranchMergeBaseChangedFiles(
repository: Repository,
baseBranchName: string,
comparisonBranchName: string,
latestComparisonBranchCommitRef: string
): Promise<IChangesetData | null> {
const baseArgs = [
'diff',
'--merge-base',
'-C',
'-M',
'-z',
'--raw',
'--numstat',
'--end-of-options',
baseBranchName,
comparisonBranchName,
'--',
]
const mergeBaseCommit = await getMergeBase(
repository,
baseBranchName,
comparisonBranchName
)
if (mergeBaseCommit === null) {
return null
}
const result = await git(
baseArgs,
repository.path,
'getBranchMergeBaseChangedFiles'
)
return parseRawLogWithNumstat(
result.stdout,
`${latestComparisonBranchCommitRef}`,
mergeBaseCommit
)
}

Workaround

  1. Make sure you are on the default branch. Otherwise, switch there.
  2. Fetch origin.
  3. Create a new branch from the default named e.g. upstream-main.
  4. Publish the branch just created.
  5. Focus on the menu bar →
    Click Repository → View on GitHub.
  6. On the repo's GitHub page, next to Fork, ▼ → your remote origin repo
  7. Change the default branch to the one created in Step 3.
  8. Fetch origin.

The preview now uses upstream-main as its base, so the commit count and diffstat match what is on GitHub.

Caution

This changes the fork's default branch for everyone using that fork, and new clones will check out upstream-main instead of main. Keep upstream-main in sync with upstream/main, otherwise the preview drifts again.

Activity

  1. changed the title [-]"Open a pull request" preview compares against the fork's default branch instead of the parent repository's default branch[/-] [+]**Open a pull request** preview compares against fork's default branch instead of parent's[/+] on Nov 4, 2026
  2. desktop-triage commented on Nov 4, 2026

    @desktop-triage

    Classification: Bug
    Priority: P3

    This is a reproducible bug, not a duplicate — the only prior searches turned up unrelated issues (#13533 "View fork on GitHub", #23073 commit-diff mixing, #22756 worktree uncommitted changes), none of which cover the PR-preview base-branch selection described here. The report includes version (3.6.10), OS (Windows 11), explicit numbered repro steps, and a clear expected-vs-actual contrast (GitHub creates the PR against upstream's default branch with one commit, but Desktop's preview computes the diff against the fork's own stale default branch, showing all of upstream's commits as "part of" the PR). A documented workaround exists (changing the fork's default branch), which supports a lower priority since the underlying upstreamDefaultBranch plumbing is already present in the codebase.

    Information Assessment:

    • Provided: version, OS, precise repro steps, screenshots showing the mismatched commit/file list, and a workaround.
    • Missing: nothing further needed to investigate — the report is self-contained and the cited source lines check out.

    Recommended Labels:

    • bug — confirmed by tracing _startPullRequest against GitStore's branch state; behavior matches the reported symptom.

    Duplicate Check: No duplicates found. Related-but-distinct: #13533 is only about adding a "View fork on GitHub" menu entry (part of this issue's workaround steps, not the bug itself).

    Suggested Next Steps: Ready for engineering review — the fix likely involves preferring upstreamDefaultBranch over defaultBranch when starting a PR preview for a fork contributing to its parent.


    Initial hypothesis: AppStore._startPullRequest (

    public async _startPullRequest(repository: Repository) {
    const { tip, defaultBranch } =
    this.repositoryStateCache.get(repository).branchesState
    if (tip.kind !== TipState.Valid) {
    // Shouldn't even be able to get here if so - just a type check
    return
    }
    const currentBranch = tip.branch
    this._initializePullRequestPreview(repository, defaultBranch, currentBranch)
    ) destructures only tip and defaultBranch from branchesState and always passes the fork's own defaultBranch into _initializePullRequestPreview, which then diffs currentBranch against that branch via gitStore.getCommitsBetweenBranches (
    public async getCommitsBetweenBranches(
    baseBranch: Branch,
    comparisonBranch: Branch
    ): Promise<ReadonlyArray<Commit>> {
    const revisionRange = revRange(baseBranch.name, comparisonBranch.name)
    const commits = await this.performFailableOperation(() =>
    getCommits(this.repository, revisionRange)
    ) and getBranchMergeBaseChangedFiles. Meanwhile, GitStore.refreshDefaultBranch (
    public async refreshDefaultBranch() {
    this._defaultBranch = await findDefaultBranch(
    this.repository,
    this.allBranches,
    this.defaultRemote?.name
    )
    // The upstream default branch is only relevant for forked GitHub repos when
    // the fork behavior is contributing to the parent.
    if (
    !isRepositoryWithForkedGitHubRepository(this.repository) ||
    getNonForkGitHubRepository(this.repository) ===
    this.repository.gitHubRepository
    ) {
    this._upstreamDefaultBranch = null
    return
    }
    const upstreamDefaultBranch =
    (await getRemoteHEAD(this.repository, UpstreamRemoteName)) ??
    getDefaultBranch()
    this._upstreamDefaultBranch =
    this._allBranches.find(
    b =>
    b.type === BranchType.Remote &&
    ) already computes a separate upstreamDefaultBranch specifically for forked repos "contributing to the parent," and this value is exposed on branchesState (
    defaultBranch: gitStore.defaultBranch,
    upstreamDefaultBranch: gitStore.upstreamDefaultBranch,
    ) but is never consulted by _startPullRequest. By contrast, _openCreatePullRequestInBrowser (
    }
    const { parent, owner, name, htmlURL } = gitHubRepository
    const isForkContributingToParent =
    isForkedRepositoryContributingToParent(repository)
    ) and showPullRequestPopup's base-branch filtering (
    const remote = isForkedRepositoryContributingToParent(repository)
    ? UpstreamRemoteName
    : gitStore.defaultRemote?.name
    const prBaseBranches = allBranches.filter(
    ) both explicitly check isForkedRepositoryContributingToParent(repository) before deciding which remote/branch to target. This asymmetry — the actual "Create pull request" browser action and base-branch dropdown account for the fork/upstream distinction, but the initial preview computation does not — is consistent with the reported symptom: the preview diffs against the fork's stale main, while GitHub itself (and the rest of Desktop's PR UI) correctly resolves against the parent's default branch. If the fork's default branch is behind, this makes every upstream commit appear to be part of the PR in the preview only.

    Generated by Issue Triage (skills-driven) for #23120 · auto · 55.8 AIC · ⊞ 4.7K · ◷

  3. tidy-dev commented on Nov 4, 2026

    @tidy-dev
    Contributor

    Could you let us know which fork behavior is selected? In Desktop, open Repository settings → Fork behavior. Under I'll be using this fork…, the options are To contribute to the parent repository and For my own purposes. Which one is selected?

  4. added
    more-info-needed
    on Nov 4, 2026
  5. PtJade-Ceramic commented on Nov 5, 2026

    @PtJade-Ceramic
    ContributorAuthor

    4. Could you let us know which fork behavior is selected? In Desktop, open Repository settings → Fork behavior. Under I'll be using this fork…, the options are To contribute to the parent repository and For my own purposes. Which one is selected?

    To contribute to the parent repository.

    Another problem found out of the scope of this issue

    BTW the sidebar there does not respond to Home/End/PageUp/PageDown, which may be reported as another issue.

  6. removed
    more-info-needed
    on Nov 5, 2026
  7. added
    bug
    priority-3
    on Nov 9, 2026
  8. DylanDevelops commented on Nov 9, 2026

    @DylanDevelops
    Contributor

    I believe I fixed this issue in #23151! Let me know if I am understanding the problem correctly.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpriority-3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions