jesseduffield/lazygit · warning

Invalid upstream. Must be in the format '<remote> <branchnam

Error message

Invalid upstream. Must be in the format '<remote> <branchname>'

What it means

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.

Source

Thrown at pkg/gui/controllers/helpers/upstream_helper.go:31

	getRemoteBranchesSuggestionsFunc func(string) func(string) []*types.Suggestion
}

func NewUpstreamHelper(
	c *HelperCommon,
	getRemoteBranchesSuggestionsFunc func(string) func(string) []*types.Suggestion,
) *UpstreamHelper {
	return &UpstreamHelper{
		c:                                c,
		getRemoteBranchesSuggestionsFunc: getRemoteBranchesSuggestionsFunc,
	}
}

func (self *UpstreamHelper) ParseUpstream(upstream string) (string, string, error) {
	var upstreamBranch, upstreamRemote string
	split := strings.Split(upstream, " ")
	if len(split) != 2 {
		return "", "", errors.New(self.c.Tr.InvalidUpstream)
	}

	upstreamRemote = split[0]
	upstreamBranch = split[1]

	return upstreamRemote, upstreamBranch, nil
}

func (self *UpstreamHelper) promptForUpstream(initialContent string, onConfirm func(string) error) error {
	self.c.Prompt(types.PromptOpts{
		Title:               self.c.Tr.EnterUpstream,
		InitialContent:      initialContent,
		FindSuggestionsFunc: self.getRemoteBranchesSuggestionsFunc(" "),
		HandleConfirm:       onConfirm,
	})

	return nil
}

View on GitHub (pinned to c477a2959b)

Solutions

  1. Enter exactly two space-separated tokens: the remote name then the branch name, e.g. 'origin feature'.
  2. Use the suggestions popup (type the remote then pick a branch) to insert the valid form.
  3. If you meant a slash-form, drop the remote prefix: branch 'feature' on remote 'origin'.

Example fix

// before
split := strings.Split(upstream, " ")
if len(split) != 2 {
    return "", "", errors.New(self.c.Tr.InvalidUpstream)
}

// after (also accept the common slash form, after trimming):
upstream = strings.TrimSpace(upstream)
var remote, branch string
if parts := strings.Fields(upstream); len(parts) == 2 {
    remote, branch = parts[0], parts[1]
} else if i := strings.Index(upstream, "/"); i > 0 {
    remote, branch = upstream[:i], upstream[i+1:]
} else {
    return "", "", errors.New(self.c.Tr.InvalidUpstream)
}
Defensive patterns

Strategy: validation

Validate before calling

// pre-validate before submitting the prompt:
if len(strings.Fields(strings.TrimSpace(upstream))) != 2 {
    // reject or normalize (e.g. convert 'origin/x' to 'origin x')
}

Type guard

func isValidUpstream(s string) bool {
    p := strings.Fields(strings.TrimSpace(s))
    return len(p) == 2 && p[0] != "" && p[1] != "" && !strings.ContainsAny(p[1], " /")
}

Prevention

When it happens

Trigger: 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.

Common situations: Users habituated to git's branch@{upstream} or refs/remotes/<remote>/<branch> notation; trailing spaces; copy-pasting a full ref into the prompt.

Related errors


AI-assisted analysis of jesseduffield/lazygit@c477a2959b (2026-08-15). Data as JSON: /api/errors/151b93de9151f3ab. Report an issue: GitHub.