{"record":{"id":"f1cfd1c457f9f28c","repo":"golang/go","slug":"git-credential-fill-failed-url-s-w-s","errorCode":null,"errorMessage":"'git credential fill' failed (url=%s): %w\n%s","messagePattern":"'git credential fill' failed \\(url=(.+?)\\): %w\n(.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/auth/gitauth.go","lineNumber":50,"sourceCode":"// The caller must not mutate the header.\nfunc runGitAuth(client *http.Client, dir, url string) (string, http.Header, error) {\n\tif url == \"\" {\n\t\t// No explicit url was passed, but 'git credential'\n\t\t// provides no way to enumerate existing credentials.\n\t\t// Wait for a request for a specific url.\n\t\treturn \"\", nil, fmt.Errorf(\"no explicit url was passed\")\n\t}\n\tif dir == \"\" {\n\t\t// Prevent config-injection attacks by requiring an explicit working directory.\n\t\t// See https://golang.org/issue/29230 for details.\n\t\tpanic(\"'git' invoked in an arbitrary directory\") // this should be caught earlier.\n\t}\n\tcmd := exec.Command(\"git\", \"credential\", \"fill\")\n\tcmd.Dir = dir\n\tcmd.Stdin = strings.NewReader(fmt.Sprintf(\"url=%s\\n\", url))\n\tout, err := cmd.CombinedOutput()\n\tif err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"'git credential fill' failed (url=%s): %w\\n%s\", url, err, out)\n\t}\n\tparsedPrefix, username, password := parseGitAuth(out)\n\tif parsedPrefix == \"\" {\n\t\treturn \"\", nil, fmt.Errorf(\"'git credential fill' failed for url=%s, could not parse url\\n\", url)\n\t}\n\t// Check that the URL Git gave us is a prefix of the one we requested.\n\tif !strings.HasPrefix(url, parsedPrefix) {\n\t\treturn \"\", nil, fmt.Errorf(\"requested a credential for %s, but 'git credential fill' provided one for %s\\n\", url, parsedPrefix)\n\t}\n\treq, err := http.NewRequest(\"HEAD\", parsedPrefix, nil)\n\tif err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"internal error constructing HTTP HEAD request: %v\\n\", err)\n\t}\n\treq.SetBasicAuth(username, password)\n\t// Asynchronously validate the provided credentials using a HEAD request,\n\t// allowing the git credential helper to update its cache without blocking.\n\t// This avoids repeatedly prompting the user for valid credentials.\n\t// This is a best-effort update; the primary validation will still occur","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/auth/gitauth.go#L32-L68","documentation":"Returned by runGitAuth when `exec.Command(\"git\", \"credential\", \"fill\")` (run with cmd.Dir = dir and `url=<url>` on stdin) fails via CombinedOutput. The error wraps the underlying exec error with %w and appends git's combined stdout/stderr with %s, so the message shows both why git failed and what git printed.","triggerScenarios":"git is not installed or not on PATH; `git credential fill` exits non-zero because no credential helper can satisfy the request; the helper errors; git prompts interactively in a non-TTY and aborts.","commonSituations":"No credential helper configured for the host; expired/revoked token; git version too old; helper lock contention; corporate proxy requiring credentials git doesn't have.","solutions":["Configure a credential helper: `git config --global credential.helper manager` (or store/osxkeychain/cache).","Pre-approve the credential so `git credential fill` succeeds: `printf 'protocol=https\\nhost=example.com\\nusername=u\\npassword=p\\n' | git credential approve`.","Verify git is installed: `git --version`.","Run `go get -x <url>` to read the wrapped git output in the message."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Verify git credential fill works for the URL ahead of time.\ncmd := exec.Command(\"git\", \"credential\", \"fill\")\ncmd.Stdin = strings.NewReader(fmt.Sprintf(\"url=%s\\n\", url))\nif out, err := cmd.CombinedOutput(); err != nil {\n    return fmt.Errorf(\"git credential fill failed: %w\\n%s\", err, out)\n}","typeGuard":null,"tryCatchPattern":"// Inspect the wrapped exec error and git output.\nif prefix, header, err := runGitAuth(client, dir, url); err != nil {\n    log.Printf(\"git auth failed for %s: %v\", url, err)\n    // fall back to another GOAUTH method\n} else {\n    storeCredential(prefix, header)\n}","preventionTips":["Configure a git credential helper (store/manager/osxkeychain/cache).","Pre-approve credentials with `git credential approve`.","Ensure git is installed and on PATH.","Avoid non-interactive helpers that require a TTY."],"tags":["go-toolchain","goauth","git","authentication","credentials","exec"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}