jesseduffield/lazygit · warning
This branch doesn't exist on remote. You need to push it to
Error message
This branch doesn't exist on remote. You need to push it to remote first.
What it means
Returned by BranchesController.getPullRequestURL (branches_controller.go:473) via Tr.NoBranchOnRemote. Even with a tracking config, the PR URL is built from the branch's remote existence; Git.Remote.CheckRemoteBranchExists (ls-remote style check) reports the branch is absent on the remote, so lazygit refuses because the hosting service would 404.
Source
Thrown at pkg/gui/controllers/branches_controller.go:473
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)
if !branchExistsOnRemote {
return "", errors.New(self.c.Tr.NoBranchOnRemote)
}
return self.c.Helpers().Host.GetPullRequestURL(branch.Name, "")
}
func (self *BranchesController) copyPullRequestURL() error {
url, err := self.getPullRequestURL()
if err != nil {
return err
}
self.c.LogAction(self.c.Tr.Actions.CopyPullRequestURL)
if err := self.c.OS().CopyToClipboard(url); err != nil {
return err
}
self.c.Toast(self.c.Tr.PullRequestURLCopiedToClipboard)
return nilView on GitHub (pinned to c477a2959b)
Solutions
- Push the branch: 'git push origin <branch>', then retry
- If the remote branch was deleted on purpose and you still want a PR, re-push or recreate the remote branch
- Fix a stale upstream name with 'git branch --set-upstream-to=origin/<actual-remote-branch>'
- Verify with 'git ls-remote --heads origin' that the branch is present
Example fix
# shell fix git ls-remote --heads origin | grep $(git branch --show-current) || git push origin $(git branch --show-current)
Defensive patterns
Strategy: validation
Validate before calling
// Verify remote existence before offering the PR action:
// git ls-remote --heads origin <branch> returning a hash means it exists
func remoteBranchExists(remote, branch string) bool {
out, err := exec.Command("git", "ls-remote", "--heads", remote, branch).Output()
return err == nil && len(strings.Fields(string(out))) > 0
} Try / catch
if _, err := getPullRequestURL(); err != nil && strings.Contains(err.Error(), "doesn't exist on remote") {
// push then retry
_ = pushBranch()
} Prevention
- Push immediately after creating branches you intend to PR
- Use 'git ls-remote --heads origin' to confirm remote state when in doubt
- Fix stale upstream names after remote branch renames
When it happens
Trigger: Invoking view/copy PR URL ('o' variants) on a branch whose remote-tracking ref exists locally but that CheckRemoteBranchExists cannot find on the actual remote — e.g. the remote branch was deleted, the upstream points to a stale name, or the push never happened.
Common situations: Branch deleted on the remote via the hosting UI but tracked locally; upstream renamed; shallow/limited-fetch clones where remote refs are missing; network hiccup making the remote check fail closed.
Related errors
- Cannot open a pull request for a branch with no upstream
- You have already checked out this branch
- Cannot fast-forward a branch with no upstream
- No pull request found for this branch
- Some of the selected branches are checked out by other workt
AI-assisted analysis of jesseduffield/lazygit@c477a2959b (2026-08-15).
Data as JSON: /api/errors/bed6947e66f07c23.
Report an issue: GitHub.