jesseduffield/lazygit · warning
Cannot open a pull request for a branch with no upstream
Error message
Cannot open a pull request for a branch with no upstream
What it means
Returned by BranchesController.handleCreatePullRequest (branches_controller.go:453) via Tr.PullRequestNoUpstream. Creating a PR requires a remote branch to target; if the selected branch's IsTrackingRemote() is false (no upstream configured), lazygit cannot build the PR URL and reports this.
Source
Thrown at pkg/gui/controllers/branches_controller.go:453
}
func (self *BranchesController) promptToCheckoutWorktree(worktree *models.Worktree) error {
prompt := utils.ResolvePlaceholderString(self.c.Tr.AlreadyCheckedOutByWorktree, map[string]string{
"worktreeName": worktree.Name,
})
return self.c.ConfirmIf(!self.c.UserConfig().Gui.SkipSwitchWorktreeOnCheckoutWarning, types.ConfirmOpts{
Title: self.c.Tr.SwitchToWorktree,
Prompt: prompt,
HandleConfirm: func() error {
return self.c.Helpers().Worktree.Switch(worktree, context.LOCAL_BRANCHES_CONTEXT_KEY)
},
})
}
func (self *BranchesController) handleCreatePullRequest(selectedBranch *models.Branch) error {
if !selectedBranch.IsTrackingRemote() {
return errors.New(self.c.Tr.PullRequestNoUpstream)
}
return self.createPullRequest(selectedBranch.UpstreamBranch, "")
}
func (self *BranchesController) handleCreatePullRequestMenu(selectedBranch *models.Branch) error {
checkedOutBranch := self.c.Helpers().Refs.GetCheckedOutRef()
return self.createPullRequestMenu(selectedBranch, checkedOutBranch)
}
func (self *BranchesController) getPullRequestURL() (string, error) {
branch := self.context().GetSelected()
if pr, ok := self.c.Model().PullRequestsMap[branch.Name]; ok {
return pr.Url, nil
}
branchExistsOnRemote := self.c.Git().Remote.CheckRemoteBranchExists(branch.Name)
View on GitHub (pinned to c477a2959b)
Solutions
- Push with upstream first: 'git push -u origin <branch>' (lazygit's push does this when the branch has no upstream)
- Or set upstream manually: 'git branch --set-upstream-to=origin/<branch>' if the remote branch already exists
- Then retry create pull request from the branches panel
Example fix
# shell fix git push -u origin $(git branch --show-current) # then retry 'o' on the branch in lazygit
Defensive patterns
Strategy: validation
Validate before calling
func branchReadyForPR(b *models.Branch) bool {
return b.IsTrackingRemote()
} Prevention
- Push new branches with -u as a habit (lazygit prompts for this on first push)
- Check the upstream column in the branches panel before creating PRs
- After remote ref cleanup, re-establish tracking before PR actions
When it happens
Trigger: Pressing 'o'/'O' (create PR) on a locally created branch that was never pushed with -u, or whose upstream tracking was removed. IsTrackingRemote checks that Pushble/Trackable remote-tracking state exists.
Common situations: New feature branches created in lazygit but not yet pushed; branches after deleting the remote-tracking ref; working offline after cloning with --single-branch so other branches lack upstream config.
Related errors
- This branch doesn't exist on remote. You need to push it to
- Cannot fast-forward a branch with no upstream
- Must specify a remote if specifying a branch
- You have already checked out this branch
- Cannot fast-forward a branch whose remote is not registered
AI-assisted analysis of jesseduffield/lazygit@c477a2959b (2026-08-15).
Data as JSON: /api/errors/e64b196703eaf61c.
Report an issue: GitHub.