{"record":{"id":"0ee6e6ce5146120b","repo":"golang/go","slug":"unable-to-resolve-git-version-w","errorCode":null,"errorMessage":"unable to resolve git version: %w","messagePattern":"unable to resolve git version: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modfetch/codehost/git.go","lineNumber":97,"sourceCode":"\tunlock, err := r.mu.Lock()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer unlock()\n\n\tif _, err := os.Stat(filepath.Join(r.dir, \"objects\")); err != nil {\n\t\trepoSha256Hash := false\n\t\tif refs, lrErr := r.loadRefs(ctx); lrErr == nil {\n\t\t\t// Check any ref's hash, it doesn't matter which; they won't be mixed\n\t\t\t// between sha1 and sha256 for the moment.\n\t\t\tfor _, refHash := range refs {\n\t\t\t\trepoSha256Hash = len(refHash) == (256 / 4)\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tgitSupportsSHA256, gitVersErr := gitSupportsSHA256()\n\t\tif gitVersErr != nil {\n\t\t\treturn nil, fmt.Errorf(\"unable to resolve git version: %w\", gitVersErr)\n\t\t}\n\t\tobjFormatFlag := []string{}\n\t\t// If git is sufficiently recent to support sha256,\n\t\t// always initialize with an explicit object-format.\n\t\tif repoSha256Hash {\n\t\t\t// We always set --object-format=sha256 if the repo\n\t\t\t// we're cloning uses sha256 hashes because if the git\n\t\t\t// version is too old, it'll fail either way, so we\n\t\t\t// might as well give it one last chance.\n\t\t\tobjFormatFlag = []string{\"--object-format=sha256\"}\n\t\t} else if gitSupportsSHA256 {\n\t\t\tobjFormatFlag = []string{\"--object-format=sha1\"}\n\t\t}\n\t\tif _, err := Run(ctx, r.dir, \"git\", \"init\", \"--bare\", objFormatFlag); err != nil {\n\t\t\tos.RemoveAll(r.dir)\n\t\t\treturn nil, err\n\t\t}\n\t\t// We could just say git fetch https://whatever later,","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modfetch/codehost/git.go#L79-L115","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before: minimal image without git\nFROM alpine\nRUN go build ./...\n# after\nFROM alpine\nRUN apk add --no-cache git\nRUN go build ./...","handlingStrategy":"validation","validationCode":"func validateGitAvailable() error {\n    cmd := exec.Command(\"git\", \"--version\")\n    out, err := cmd.Output()\n    if err != nil {\n        return fmt.Errorf(\"git not found or not executable: %w\", err)\n    }\n    if !strings.HasPrefix(strings.TrimSpace(string(out)), \"git version\") {\n        return fmt.Errorf(\"unexpected git version output: %q\", out)\n    }\n    return nil\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["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."],"tags":["git","dependencies","sha256","environment","version-detection"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}