golang/go · error
unable to resolve git version: %w
Error message
unable to resolve git version: %w
What it means
Thrown by newGitRepo when gitSupportsSHA256() returns an error. That helper runs 'git version' to detect whether the installed git is new enough to support SHA-256 object format (minGitSHA256Vers). If git is not installed, not on PATH, or 'git version' output can't be parsed, this error wraps the underlying failure.
Source
Thrown at src/cmd/go/internal/modfetch/codehost/git.go:97
unlock, err := r.mu.Lock()
if err != nil {
return nil, err
}
defer unlock()
if _, err := os.Stat(filepath.Join(r.dir, "objects")); err != nil {
repoSha256Hash := false
if refs, lrErr := r.loadRefs(ctx); lrErr == nil {
// Check any ref's hash, it doesn't matter which; they won't be mixed
// between sha1 and sha256 for the moment.
for _, refHash := range refs {
repoSha256Hash = len(refHash) == (256 / 4)
break
}
}
gitSupportsSHA256, gitVersErr := gitSupportsSHA256()
if gitVersErr != nil {
return nil, fmt.Errorf("unable to resolve git version: %w", gitVersErr)
}
objFormatFlag := []string{}
// If git is sufficiently recent to support sha256,
// always initialize with an explicit object-format.
if repoSha256Hash {
// We always set --object-format=sha256 if the repo
// we're cloning uses sha256 hashes because if the git
// version is too old, it'll fail either way, so we
// might as well give it one last chance.
objFormatFlag = []string{"--object-format=sha256"}
} else if gitSupportsSHA256 {
objFormatFlag = []string{"--object-format=sha1"}
}
if _, err := Run(ctx, r.dir, "git", "init", "--bare", objFormatFlag); err != nil {
os.RemoveAll(r.dir)
return nil, err
}
// We could just say git fetch https://whatever later,View on GitHub (pinned to b6b368adc5)
Solutions
- Install git: 'apt-get install git' / 'apk add git' / 'yum install git'.
- Ensure git is on PATH: 'which git && git --version'.
- Upgrade git to at least minGitSHA256Vers if the installed version is too old to parse.
- In containers, add 'RUN apk add --no-cache git' or equivalent.
Example fix
# before: minimal image without git FROM alpine RUN go build ./... # after FROM alpine RUN apk add --no-cache git RUN go build ./...
Defensive patterns
Strategy: validation
Validate before calling
func validateGitAvailable() error {
cmd := exec.Command("git", "--version")
out, err := cmd.Output()
if err != nil {
return fmt.Errorf("git not found or not executable: %w", err)
}
if !strings.HasPrefix(strings.TrimSpace(string(out)), "git version") {
return fmt.Errorf("unexpected git version output: %q", out)
}
return nil
} Type guard
null
Try / catch
null
Prevention
- Install git in all build/CI images: 'apk add git' / 'apt-get install git'.
- Add a pre-build check: 'command -v git || { echo "git required"; exit 1; }'.
- Pin a known-good git version in CI to avoid regressions.
- Don't alias or wrap git with scripts that alter version output.
When it happens
Trigger: Initializing a cached git repo (newGitRepo remote path) on a system where the 'git' binary is missing, too old to report a version, or returns unparseable output. The error occurs before any clone/fetch attempt.
Common situations: Minimal docker/alpine images without git installed; CI runners with git missing from PATH; git replaced by a wrapper script that doesn't emit standard version output; corrupted git installation.
Related errors
- git version extraction regexp did not match version line: %q
- failed to execute git version: %w
- globalThis.crypto is not available, polyfill required (crypt
- globalThis.performance is not available, polyfill required (
- globalThis.TextEncoder is not available, polyfill required
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/0ee6e6ce5146120b.
Report an issue: GitHub.