jesseduffield/lazygit · error

Error in commitPrefix pattern: %s

Error message

Error in commitPrefix pattern: %s

What it means

WorkingTreeHelper (pkg/gui/controllers/helpers/working_tree_helper.go) builds the initial commit message from a commitPrefix pattern: for each matching config entry it regexp.Compile's the pattern and, on compile failure, wraps the Go regex error with the CommitPrefixPatternError prefix. Only a syntactically invalid Go regexp triggers it — no match simply skips the entry.

Source

Thrown at pkg/gui/controllers/helpers/working_tree_helper.go:216

	}
	return self.HandleCommitPressWithMessage(initialMessage, true)
}

func (self *WorkingTreeHelper) HandleCommitPress() error {
	var initialMessage string
	preservedMessage := self.c.Contexts().CommitMessage.GetPreservedMessageAndLogError()
	if preservedMessage == "" {
		commitPrefixConfigs := self.commitPrefixConfigsForRepo()
		for _, commitPrefixConfig := range commitPrefixConfigs {
			prefixPattern := commitPrefixConfig.Pattern
			if prefixPattern == "" {
				continue
			}
			prefixReplace := commitPrefixConfig.Replace
			branchName := self.refHelper.GetCheckedOutRef().Name
			rgx, err := regexp.Compile(prefixPattern)
			if err != nil {
				return fmt.Errorf("%s: %s", self.c.Tr.CommitPrefixPatternError, err.Error())
			}

			if rgx.MatchString(branchName) {
				initialMessage = rgx.ReplaceAllString(branchName, prefixReplace)
				break
			}
		}
	}

	return self.HandleCommitPressWithMessage(initialMessage, false)
}

func (self *WorkingTreeHelper) WithEnsureCommittableFiles(handler func() error) error {
	if len(self.c.Model().Files) == 0 {
		return errors.New(self.c.Tr.NoFilesStagedTitle)
	}

	if !self.AnyStagedFiles() {

View on GitHub (pinned to c477a2959b)

Solutions

  1. Fix the pattern in the user config so it compiles as a Go regexp (balance groups, escape metacharacters with a double backslash in YAML).
  2. Test it quickly: go run with regexp.MustCompile, or any online Go-regex checker — JS/PCRE flavors differ.
  3. If prefixes are unwanted, remove the commitPrefix section entirely instead of leaving a broken pattern.

Example fix

# before
git:
  commitPrefix:
    - pattern: "^feature/(\w+"
      replacement: "[$1] "

# after
git:
  commitPrefix:
    - pattern: "^feature/(\w+)"
      replacement: "[$1] "
Defensive patterns

Strategy: validation

Validate before calling

// Compile-check prefix patterns at config load time:
for _, p := range cfg.Git.CommitPrefix {
	if _, err := regexp.Compile(p.Pattern); err != nil {
		return fmt.Errorf("commitPrefix pattern %q invalid: %w", p.Pattern, err)
	}
}

Prevention

When it happens

Trigger: Setting git.commitPrefix[n].pattern (or a repo-specific commitPrefixes entry) to an invalid Go regex such as 'feature/(\w+' (unclosed group) or '{2,1}' (bad repetition) in the user config, then pressing the commit key while no preserved message exists.

Common situations: Patterns written for PCRE with unsupported syntax; unescaped parentheses/braces; missing closing group when copying from issue templates; repo-specific commitPrefixes in .lazygitconfig with a typo.

Related errors


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