{"record":{"id":"89be9f8966e1c088","repo":"jesseduffield/lazygit","slug":"upstream-branch-s-s-not-found-if-you-expect-it","errorCode":null,"errorMessage":"upstream branch %s/%s not found.\nIf you expect it to exist, you should fetch (with 'f').\nOtherwise, you should push (with 'shift+P')","messagePattern":"upstream branch (.+?)/(.+?) not found\\.\nIf you expect it to exist, you should fetch \\(with 'f'\\)\\.\nOtherwise, you should push \\(with 'shift\\+P'\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gui/controllers/sync_controller.go","lineNumber":143,"sourceCode":"\t\t\t\treturn err\n\t\t\t}\n\n\t\t\treturn self.PullAux(currentBranch, PullFilesOptions{Action: action})\n\t\t})\n\t}\n\n\treturn self.PullAux(currentBranch, PullFilesOptions{Action: action})\n}\n\nfunc (self *SyncController) setCurrentBranchUpstream(upstream string) error {\n\tupstreamRemote, upstreamBranch, err := self.c.Helpers().Upstream.ParseUpstream(upstream)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif err := self.c.Git().Branch.SetCurrentBranchUpstream(upstreamRemote, upstreamBranch); err != nil {\n\t\tif strings.Contains(err.Error(), \"does not exist\") {\n\t\t\treturn fmt.Errorf(\n\t\t\t\t\"upstream branch %s/%s not found.\\nIf you expect it to exist, you should fetch (with 'f').\\nOtherwise, you should push (with 'shift+P')\",\n\t\t\t\tupstreamRemote, upstreamBranch,\n\t\t\t)\n\t\t}\n\t\treturn err\n\t}\n\treturn nil\n}\n\ntype PullFilesOptions struct {\n\tUpstreamRemote  string\n\tUpstreamBranch  string\n\tFastForwardOnly bool\n\tAction          string\n}\n\nfunc (self *SyncController) PullAux(currentBranch *models.Branch, opts PullFilesOptions) error {\n\treturn self.c.WithInlineStatus(currentBranch, types.ItemOperationPulling, context.LOCAL_BRANCHES_CONTEXT_KEY, func(task gocui.Task) error {","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/jesseduffield/lazygit/blob/c477a2959b229fbf3284be0d4d2904ab61ec3c94/pkg/gui/controllers/sync_controller.go#L125-L161","documentation":"SyncController.setCurrentBranchUpstream (pkg/gui/controllers/sync_controller.go) runs git branch --set-upstream-to=<remote>/<branch>; if git fails with an error containing 'does not exist' it rewrites it into this actionable hint: the upstream ref is unknown locally, so either fetch it ('f') or push the branch ('shift+P') to create it on the remote first.","triggerScenarios":"Setting an upstream for a branch (e.g. via the upstream-options menu) whose remote-tracking ref refs/remotes/<remote>/<branch> does not exist locally — because the branch was never pushed, or the remote has it but it was never fetched.","commonSituations":"New local branches before first push; after cloning a repo whose remote gained new branches that were never fetched; working offline so the fetch fails silently; upstream names with typos so the ref genuinely does not exist.","solutions":["Press 'f' (fetch) to pull refs from the remote, then set the upstream again.","If the branch does not exist on the remote yet, push it first ('shift+P' pushes with upstream, or use the push-and-set-upstream option).","Double-check the remote/branch spelling in the upstream prompt before confirming."],"exampleFix":"# terminal equivalent\n# before (fails): upstream not known locally\ngit branch --set-upstream-to=origin/feature-x feature-x\n\n# after\ngit fetch origin\ngit branch --set-upstream-to=origin/feature-x feature-x\n# or, if never pushed:\ngit push -u origin feature-x","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := set_upstream_to(\"origin/feature-x\"); err != nil {\n\tif strings.Contains(err.Error(), \"not found\") {\n\t\t_ = fetch(\"origin\")            // then retry once\n\t\terr = set_upstream_to(\"origin/feature-x\")\n\t}\n\tif err != nil {\n\t\t_ = push_with_upstream()        // branch never pushed: push -u creates it\n\t}\n}","preventionTips":["Push new branches with `git push -u` (lazygit: 'shift+P' / upstream options) so tracking refs exist.","Fetch after cloning or when teammates create branches you want to track.","Confirm remote/branch spelling in the upstream prompt before accepting."],"tags":["git","upstream","sync","fetch"],"backgroundTag":null,"analyzedSha":"c477a2959b229fbf3284be0d4d2904ab61ec3c94","analyzedAt":"2026-08-15T08:34:32.451Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}