mislav/hub · error
Can't find remote for %s
Error message
Can't find remote for %s
What it means
gh pulls the head branch's tracking remote to build the "from" side of a pull request. When `--push` is requested but no remote that tracks the head branch exists, `remote` is nil and pullRequest aborts with this error, since pushing to create the head ref is impossible without a remote.
Source
Thrown at commands/pull_request.go:244
Title: "pull request",
}
baseTracking := base
headTracking := head
remote := baseRemote
if remote != nil {
baseTracking = fmt.Sprintf("%s/%s", remote.Name, base)
}
if remote == nil || !baseProject.SameAs(headProject) {
remote, _ = localRepo.RemoteForProject(headProject)
}
if remote != nil {
headTracking = fmt.Sprintf("%s/%s", remote.Name, head)
}
if flagPullRequestPush && remote == nil {
utils.Check(fmt.Errorf("Can't find remote for %s", head))
}
messageBuilder.AddCommentedSection(fmt.Sprintf(`Requesting a pull to %s from %s
Write a message for this pull request. The first block
of text is the title and the rest is the description.`, fullBase, fullHead))
flagPullRequestMessage := args.Flag.AllValues("--message")
flagPullRequestEdit := args.Flag.Bool("--edit")
flagPullRequestIssue := args.Flag.Value("--issue")
if !args.Flag.HasReceived("--issue") && args.ParamsSize() > 0 {
flagPullRequestIssue = parsePullRequestIssueNumber(args.GetParam(0))
}
if len(flagPullRequestMessage) > 0 {
messageBuilder.Message = strings.Join(flagPullRequestMessage, "\n\n")
messageBuilder.Edit = flagPullRequestEdit
} else if args.Flag.HasReceived("--file") {View on GitHub (pinned to 5c547ed804)
Solutions
- Set an upstream for the branch: git branch --set-upstream-to=<remote>/<branch>, or push once with `git push -u origin <head>` then rerun.
- Run without `--push` after pushing the branch manually with git push -u.
- Verify remotes with `git remote -v` and re-add the missing remote (`gh repo set-default` / `git remote add origin ...`).
Example fix
// before (branch has no tracking remote) gh pr create --push // after git push -u origin feature-branch gh pr create --push
Defensive patterns
Strategy: validation
Validate before calling
remote := git.RemoteForBranch(head)
if remote == nil {
fmt.Println("no tracking remote for", head, "— run: git push -u origin", head)
os.Exit(1)
} Prevention
- Always push new branches with -u to set upstream tracking.
- Run `git remote -v` before scripted PR creation.
- Avoid --push in scripts unless the branch is known to have an upstream.
When it happens
Trigger: Running `gh pr create --push` (flagPullRequestPush true) while `remote` resolved to nil — i.e. the current branch has no configured tracking remote / no remote named matching the head ref in the repository config.
Common situations: Branch created locally without ever pushing it and without an upstream set; repo has a single 'origin' but config points the branch tracking elsewhere; remotes were renamed or removed after cloning.
Related errors
- the current branch '%s' doesn't seem pushed to a remote
- could not determine project for head branch
- Aborted: no commits detected between %s and %s
- Aborted: no revision could be determined from '%s'
- Error: %s/%s doesn't have a wiki
AI-assisted analysis of mislav/hub@5c547ed804 (2026-09-01).
Data as JSON: /api/errors/f68466a9872f8905.
Report an issue: GitHub.