Repository navigation
[Bug]: "Commit, push & PR" can't find the open PR when the only remote isn't named origin, and fails on gh pr create #15373
Description
Before submitting
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area
apps/server
Steps to reproduce
Single-repository workflow (no fork) where the only remote is not named origin:
- Clone a repo and name its only remote something else:
git clone --origin fork https://github.com/<owner>/<repo>.git(orgit remote rename origin fork). gh repo set-default <owner>/<repo>(the same repoforkpoints to).- On branch
dev(trackingfork/dev), commit and push, then open a PRdev→mainin<owner>/<repo>. The first "Commit, push & PR" run does this fine. - Commit again and run Commit, push & PR a second time while that PR is still open.
Expected behavior
The commit and push succeed, and the PR step finds the open PR and returns it (opened_existing), as it does when the remote is named origin.
Actual behavior
The commit and push succeed, but the action ends with:
Source control provider github failed in createChangeRequest: GitHub CLI command failed.
T3 Code calls gh pr create again, and gh refuses:
a pull request for branch "dev" into branch "main" already exists:
https://github.com/<owner>/<repo>/pull/3
Cause
Same root assumption as #7382 (the remote literally named origin is treated as the base repository), but a different failure: the existing-PR lookup rejects a same-repository PR.
In resolveBranchHeadContext (apps/server/src/git/GitManager.ts), resolveRemoteRepositoryContext(cwd, "origin") returns all nulls because there is no origin remote, so isCrossRepository falls through to the fallback branch:
const isCrossRepository =
remoteRepository.repositoryNameWithOwner !== null && originRepository.repositoryNameWithOwner !== null
? /* compare */
: remoteName !== null && remoteName !== "origin" && remoteRepository.repositoryNameWithOwner !== null;
// ^ "fork" !== "origin" → true, although head and base are the same repositoryfindOpenPr then lists the PR correctly (gh pr list --head <owner>:dev / dev returns #3 with isCrossRepository: false), but matchesBranchHeadContext discards it:
if (headContext.isCrossRepository) {
if (pr.isCrossRepository === false) return false; // the real PR is dropped here
...
}runPrStep concludes that no PR exists and goes on to createChangeRequest, which fails.
Renaming the remote to origin works around it: isCrossRepository becomes false, the selector is dev, and the PR matches.
Suggested fix
Don't infer the base repository from the remote name. Use what gh already resolved (gh repo set-default / remote.<name>.gh-resolved=base, or gh repo view --json nameWithOwner) as the target repository, and treat the head as cross-repository only when the head remote's nameWithOwner differs from it. The fallback remoteName !== "origin" heuristic produces a false positive whenever the only remote has a different name. This would also cover #7382.
Impact
Minor bug or occasional failure
Version or commit
0.0.45-nightly.20261002.2584
Environment
Linux (Fedora 44 / Bluefin), desktop AppImage, gh logged in via keyring
Activity
juliusmarminge commentedon Oct 3, 2026
Note
Grok responding on behalf of Julius.
Triage
Thanks for tracing this so precisely, @netherguy4! This reproduces on current
main(00eb8f6183). It's a real lookup bug and not a duplicate of #7382.What happens
resolveBranchHeadContextinapps/server/src/git/GitManager.tsdecides whether a branch is cross-repository by comparing its remote with the remote literally namedorigin. When there's noorigin, that comparison can't run, and the fallback treats any other remote as a fork:So a same-repository checkout whose only remote is
forkgets marked cross-repository.gh pr list --head devreturns the existing PR withisCrossRepository: false, butmatchesBranchHeadContextdrops it.runPrStepthen falls through togh pr create, which fails because the PR already exists. The first run still works because creation uses the owner-qualified head, whichghaccepts for a same-repository PR. Renaming the remote tooriginavoids the fallback, which matches your workaround.#7382 is the opposite mistake. There,
originis the fork, so the same comparison decides the branch isn't cross-repository and creation sends an unqualified head.Likely fix area
ghwill target (gh repo set-default/remote.<name>.gh-resolved, orgh repo view --json nameWithOwner) instead of from the remote's name, as you suggested.remoteName !== "origin"fallback when there's nooriginto compare against.A maintainer will decide on the fix direction.