{"record":{"id":"bed6947e66f07c23","repo":"jesseduffield/lazygit","slug":"this-branch-doesn-t-exist-on-remote-you-need-to-p","errorCode":null,"errorMessage":"This branch doesn't exist on remote. You need to push it to remote first.","messagePattern":"This branch doesn't exist on remote\\. You need to push it to remote first\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/gui/controllers/branches_controller.go","lineNumber":473,"sourceCode":"\treturn self.createPullRequest(selectedBranch.UpstreamBranch, \"\")\n}\n\nfunc (self *BranchesController) handleCreatePullRequestMenu(selectedBranch *models.Branch) error {\n\tcheckedOutBranch := self.c.Helpers().Refs.GetCheckedOutRef()\n\n\treturn self.createPullRequestMenu(selectedBranch, checkedOutBranch)\n}\n\nfunc (self *BranchesController) getPullRequestURL() (string, error) {\n\tbranch := self.context().GetSelected()\n\tif pr, ok := self.c.Model().PullRequestsMap[branch.Name]; ok {\n\t\treturn pr.Url, nil\n\t}\n\n\tbranchExistsOnRemote := self.c.Git().Remote.CheckRemoteBranchExists(branch.Name)\n\n\tif !branchExistsOnRemote {\n\t\treturn \"\", errors.New(self.c.Tr.NoBranchOnRemote)\n\t}\n\n\treturn self.c.Helpers().Host.GetPullRequestURL(branch.Name, \"\")\n}\n\nfunc (self *BranchesController) copyPullRequestURL() error {\n\turl, err := self.getPullRequestURL()\n\tif err != nil {\n\t\treturn err\n\t}\n\tself.c.LogAction(self.c.Tr.Actions.CopyPullRequestURL)\n\tif err := self.c.OS().CopyToClipboard(url); err != nil {\n\t\treturn err\n\t}\n\n\tself.c.Toast(self.c.Tr.PullRequestURLCopiedToClipboard)\n\n\treturn nil","sourceCodeStart":455,"sourceCodeEnd":491,"githubUrl":"https://github.com/jesseduffield/lazygit/blob/c477a2959b229fbf3284be0d4d2904ab61ec3c94/pkg/gui/controllers/branches_controller.go#L455-L491","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# shell fix\ngit ls-remote --heads origin | grep $(git branch --show-current) || git push origin $(git branch --show-current)","handlingStrategy":"validation","validationCode":"// Verify remote existence before offering the PR action:\n// git ls-remote --heads origin <branch> returning a hash means it exists\nfunc remoteBranchExists(remote, branch string) bool {\n    out, err := exec.Command(\"git\", \"ls-remote\", \"--heads\", remote, branch).Output()\n    return err == nil && len(strings.Fields(string(out))) > 0\n}","typeGuard":null,"tryCatchPattern":"if _, err := getPullRequestURL(); err != nil && strings.Contains(err.Error(), \"doesn't exist on remote\") {\n    // push then retry\n    _ = pushBranch()\n}","preventionTips":["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"],"tags":["git","pull-request","remote","branches"],"backgroundTag":null,"analyzedSha":"c477a2959b229fbf3284be0d4d2904ab61ec3c94","analyzedAt":"2026-08-15T08:34:32.451Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}