gh repo set-default: Fix base repository
gh repo set-default records which remote repository gh should treat as the base for PR and issue commands.
On a clone with both origin and upstream, gh cannot guess the base repo; set-default removes the ambiguity and the prompt.
What it does
gh repo set-default tells gh which of the configured git remotes is the base repository for commands like gh pr create and gh issue list. It writes the choice into the local git config so later commands stop prompting.
Common usage
gh repo set-default
gh repo set-default owner/repo
gh repo set-default --viewFlags
| Flag | What it does |
|---|---|
| <owner/repo> | Set the base repository non-interactively |
| -v, --view | Print the current default base repository |
| -u, --unset | Remove the configured default |
In CI
Set GH_TOKEN. On runners that check out a fork, multiple remotes make gh prompt for a base repo, which fails headless; run gh repo set-default owner/repo non-interactively, or pass -R owner/repo on each command instead.
Common errors in CI
"could not determine base repository: please run 'gh repo set-default' to select a default remote repository" means gh found several remotes and no default; set one or use -R. set-default with no argument tries to prompt and fails headless, so always pass owner/repo in CI.