{"record":{"id":"151b93de9151f3ab","repo":"jesseduffield/lazygit","slug":"invalid-upstream-must-be-in-the-format-remote","errorCode":null,"errorMessage":"Invalid upstream. Must be in the format '<remote> <branchname>'","messagePattern":"Invalid upstream\\. Must be in the format '<remote> <branchname>'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/gui/controllers/helpers/upstream_helper.go","lineNumber":31,"sourceCode":"\n\tgetRemoteBranchesSuggestionsFunc func(string) func(string) []*types.Suggestion\n}\n\nfunc NewUpstreamHelper(\n\tc *HelperCommon,\n\tgetRemoteBranchesSuggestionsFunc func(string) func(string) []*types.Suggestion,\n) *UpstreamHelper {\n\treturn &UpstreamHelper{\n\t\tc:                                c,\n\t\tgetRemoteBranchesSuggestionsFunc: getRemoteBranchesSuggestionsFunc,\n\t}\n}\n\nfunc (self *UpstreamHelper) ParseUpstream(upstream string) (string, string, error) {\n\tvar upstreamBranch, upstreamRemote string\n\tsplit := strings.Split(upstream, \" \")\n\tif len(split) != 2 {\n\t\treturn \"\", \"\", errors.New(self.c.Tr.InvalidUpstream)\n\t}\n\n\tupstreamRemote = split[0]\n\tupstreamBranch = split[1]\n\n\treturn upstreamRemote, upstreamBranch, nil\n}\n\nfunc (self *UpstreamHelper) promptForUpstream(initialContent string, onConfirm func(string) error) error {\n\tself.c.Prompt(types.PromptOpts{\n\t\tTitle:               self.c.Tr.EnterUpstream,\n\t\tInitialContent:      initialContent,\n\t\tFindSuggestionsFunc: self.getRemoteBranchesSuggestionsFunc(\" \"),\n\t\tHandleConfirm:       onConfirm,\n\t})\n\n\treturn nil\n}","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/jesseduffield/lazygit/blob/c477a2959b229fbf3284be0d4d2904ab61ec3c94/pkg/gui/controllers/helpers/upstream_helper.go#L13-L49","documentation":"Returned by UpstreamHelper.ParseUpstream when the entered upstream string, split on single spaces, does not yield exactly two fields. lazygit stores upstreams as '<remote> <branch>' (matching git's refspec shorthand origin/main), so 'origin main master' or 'origin' or 'origin/main' (slash form) are all rejected before any git command runs.","triggerScenarios":"Using the 'set upstream / enter upstream' prompt (Branches panel, default 'u') and typing a slash-separated 'origin/feature', a bare remote, or extra spaces/words. The suggestion function normally inserts the correct two-token form; the error guards manual edits.","commonSituations":"Users habituated to git's branch@{upstream} or refs/remotes/<remote>/<branch> notation; trailing spaces; copy-pasting a full ref into the prompt.","solutions":["Enter exactly two space-separated tokens: the remote name then the branch name, e.g. 'origin feature'.","Use the suggestions popup (type the remote then pick a branch) to insert the valid form.","If you meant a slash-form, drop the remote prefix: branch 'feature' on remote 'origin'."],"exampleFix":"// before\nsplit := strings.Split(upstream, \" \")\nif len(split) != 2 {\n    return \"\", \"\", errors.New(self.c.Tr.InvalidUpstream)\n}\n\n// after (also accept the common slash form, after trimming):\nupstream = strings.TrimSpace(upstream)\nvar remote, branch string\nif parts := strings.Fields(upstream); len(parts) == 2 {\n    remote, branch = parts[0], parts[1]\n} else if i := strings.Index(upstream, \"/\"); i > 0 {\n    remote, branch = upstream[:i], upstream[i+1:]\n} else {\n    return \"\", \"\", errors.New(self.c.Tr.InvalidUpstream)\n}","handlingStrategy":"validation","validationCode":"// pre-validate before submitting the prompt:\nif len(strings.Fields(strings.TrimSpace(upstream))) != 2 {\n    // reject or normalize (e.g. convert 'origin/x' to 'origin x')\n}","typeGuard":"func isValidUpstream(s string) bool {\n    p := strings.Fields(strings.TrimSpace(s))\n    return len(p) == 2 && p[0] != \"\" && p[1] != \"\" && !strings.ContainsAny(p[1], \" /\")\n}","tryCatchPattern":null,"preventionTips":["Use the suggestions popup to insert the exact '<remote> <branch>' form","Remember lazygit wants a space, not a slash, between remote and branch"],"tags":["git","upstream","validation","input-format"],"backgroundTag":null,"analyzedSha":"c477a2959b229fbf3284be0d4d2904ab61ec3c94","analyzedAt":"2026-08-15T08:34:32.451Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}