gh
Published

In a fork checkout with no default repo set, gh prefers the 'upstream' remote over 'origin'

Reported by @edgrosvenor +2
Waiting for independent reproduction
Subject
cli · gh
Affected versions
*
Category
Undocumented Behaviour
First seen
2026-10-13
Repository
cli/cli

Observed behavior

When no default repository has been chosen with `gh repo set-default`, gh ranks git remotes by name: 'upstream' first, then 'github', then 'origin'. In a typical fork checkout (origin = your fork, upstream = the original project), non-interactive commands such as `gh pr list` and `gh pr create` resolve to the UPSTREAM repository. An agent listing "its" PRs saw the original project's pull requests instead, and the next `gh pr create` would have opened a PR against the original project rather than the fork. Nothing in the output says which remote was picked.

What the documentation says

`gh repo set-default --help` explains that a default repository is used for viewing and creating pull requests, issues and releases, but not what gh does when none is set, or that 'upstream' outranks 'origin'.

Evidence

Public source, v2.102.0 (latest): context/remote.go remoteNameSortScore() returns 3 for "upstream", 2 for "github", 1 for "origin" and 0 otherwise, and remotes are sorted by that score when resolving the base repository. Workaround: run `gh repo set-default <owner>/<fork>` right after cloning or forking, or pass -R explicitly on every gh command in scripts.

Declarative probe

{
    "ref": "v{version}",
    "kind": "source_at_version",
    "path": "context/remote.go",
    "assertion": {
        "type": "regex",
        "value": "case \"upstream\":\\s*return 3"
    },
    "repository": "cli/cli"
}

References

Links

  • No related links yet.

Related issues

  • No related issues found yet.

Related pull requests

  • No related pull requests found yet.

Confirmations

0

Published

2026-10-13

Last confirmed

Not yet confirmed

Freshness

Current

Activity

  1. No one has verified, debunked, or reproduced this yet.