golang/go · warning

git version extraction regexp did not match version line: %q

Error message

git version extraction regexp did not match version line: %q

What it means

gitVersion() ran successfully but the output did not match the regex `git version (\d+\.\d+(\.\d+)?)`. extractGitVersion returns this error with the raw output quoted. Indicates git is present but emits a non-standard version banner.

Source

Thrown at src/cmd/go/internal/modfetch/codehost/git.go:1003

	}
	return RunWithArgs(ctx, args)
}

// Capture the major, minor and (optionally) patch version, but ignore anything later
var gitVersLineExtract = regexp.MustCompile(`git version\s+(\d+\.\d+(?:\.\d+)?)`)

func gitVersion() (string, error) {
	gitOut, runErr := exec.Command("git", "version").CombinedOutput()
	if runErr != nil {
		return "v0", fmt.Errorf("failed to execute git version: %w", runErr)
	}
	return extractGitVersion(gitOut)
}

func extractGitVersion(gitOut []byte) (string, error) {
	matches := gitVersLineExtract.FindSubmatch(gitOut)
	if len(matches) < 2 {
		return "v0", fmt.Errorf("git version extraction regexp did not match version line: %q", gitOut)
	}
	return "v" + string(matches[1]), nil
}

func hasAtLeastGitVersion(minVers string) (bool, error) {
	gitVers, gitVersErr := gitVersion()
	if gitVersErr != nil {
		return false, gitVersErr
	}
	return semver.Compare(minVers, gitVers) <= 0, nil
}

const minGitSHA256Vers = "v2.29"

func gitSupportsSHA256() (bool, error) {
	return hasAtLeastGitVersion(minGitSHA256Vers)
}

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Run `git --version` manually and compare the literal first line against the expected pattern.
  2. Remove any wrapper script or alias named `git` that decorates the output.
  3. Force C locale for the go command: `LANG=C LC_ALL=C go build`.
  4. Install a stock upstream git build to replace the customised one.

Example fix

// before — wrapper prints 'MyCorp git shim\ngit version 2.30'
$ git version
// error: git version extraction regexp did not match version line: "MyCorp git shim\ngit version 2.30"

// after — call real binary directly or remove shim
Defensive patterns

Strategy: validation

Validate before calling

var gitVersLineExtract = regexp.MustCompile(`git version\s+(\d+\.\d+(?:\.\d+)?)`)

func gitVersionParses() bool {
    out, err := exec.Command("git", "version").CombinedOutput()
    if err != nil { return false }
    return gitVersLineExtract.FindSubmatch(out) != nil
}

Prevention

When it happens

Trigger: Custom git builds, wrappers named `git` that print a banner, git output redirected through a translator, or a git that prints a distribution prefix (e.g. some `git version 2.34.1.windows.1` variants are fine, but heavily modified banners are not).

Common situations: A shell alias or function named `git` shadowing the real binary; enterprise wrappers that prepend authentication notices; non-English locale forcing translation of the word 'version'; very old or very custom git forks.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/43b4154cfc2f0b04. Report an issue: GitHub.