{"record":{"id":"85de1d4ab5a86d76","repo":"GoogleContainerTools/skaffold","slug":"failed-to-lookup-s-branch-for-repo-s-w","errorCode":null,"errorMessage":"failed to lookup %s branch for repo %s: %w","messagePattern":"failed to lookup (.+?) branch for repo (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/git/gitutil.go","lineNumber":77,"sourceCode":"\tif masterExists {\n\t\treturn masterRef, nil\n\t} else if mainExists {\n\t\treturn mainRef, nil\n\t}\n\treturn \"\", fmt.Errorf(\"failed to get default branch for repo %s\", repo)\n}\n\n// BranchExists checks if branch is present in the input repo\nfunc branchExists(ctx context.Context, repoCloneURI, repo, branch string) (bool, error) {\n\tgitProgram, err := findGit()\n\tif err != nil {\n\t\treturn false, err\n\t}\n\tout, err := util.RunCmdOut(ctx, exec.Command(gitProgram, \"ls-remote\", \"--heads\", repoCloneURI, branch))\n\tif err != nil {\n\t\t// stdErr contains the error message for os related errors, git permission errors\n\t\t// and if repo doesn't exist\n\t\treturn false, fmt.Errorf(\"failed to lookup %s branch for repo %s: %w\", branch, repo, err)\n\t}\n\t// stdOut contains the branch information if the branch is present in remote repo\n\t// stdOut is empty if the repo doesn't have the input branch\n\tif strings.TrimSpace(string(out)) != \"\" {\n\t\treturn true, nil\n\t}\n\treturn false, nil\n}\n\n// getRepoDir returns the cache directory name for a remote repo\nfunc getRepoDir(g Config) (string, error) {\n\tinputs := []string{g.Repo, g.Ref}\n\thasher := sha256.New()\n\tenc := json.NewEncoder(hasher)\n\tif err := enc.Encode(inputs); err != nil {\n\t\treturn \"\", err\n\t}\n","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/git/gitutil.go#L59-L95","documentation":"branchExists runs `git ls-remote --heads <repoCloneURI> <branch>` to check whether a branch exists on the remote. If that command fails (non-zero exit), the error — OS errors, git authentication/permission errors, or a nonexistent/unreachable repo — is wrapped with this message. It is a hard failure distinct from 'branch simply absent' (empty output returns false, nil).","triggerScenarios":"Called from defaultRef during syncRepo when `git ls-remote --heads` exits non-zero: git binary issues, remote URI unreachable, bad credentials/SSH key, or repository does not exist or access denied.","commonSituations":"Private repo without SSH keys or credential helper configured; repo URL typo or repo deleted; SSH host key verification failing in CI containers; git not on PATH; firewall blocking github.com/company git server; expired PAT.","solutions":["Run `git ls-remote --heads <repoCloneURI> <branch>` manually to see the underlying git error.","Fix authentication: add SSH keys (ssh -T git@github.com), configure a credential helper/PAT, or switch the clone URI between https and ssh as appropriate.","Verify the repo URI is correct and the repository exists and is accessible to your account.","Ensure the git binary is installed and on PATH (git --version); check network/proxy/VPN access to the git host."],"exampleFix":"# before\n$ skaffold run   # fails: failed to lookup main branch ... Permission denied (publickey)\n# after\n$ ssh-keygen -t ed25519 && ssh -T git@github.com   # register key with host\ngit:\n  repo: git@github.com:org/repo   # ssh URI matching configured key","handlingStrategy":"try-catch","validationCode":"git ls-remote --heads \"$REPO_CLONE_URI\" \"$BRANCH\" >/dev/null 2>&1 \\\n  || echo \"Cannot reach repo or authenticate: check URI, SSH keys, and credentials\"\ngit --version >/dev/null 2>&1 || echo \"git not installed or not on PATH\"","typeGuard":"func isGitAuthError(err error) bool {\n    msg := err.Error()\n    return strings.Contains(msg, \"Permission denied\") ||\n        strings.Contains(msg, \"Authentication failed\") ||\n        strings.Contains(msg, \"could not read Username\")\n}","tryCatchPattern":"path, err := git.SyncRepo(ctx, cfg, opts)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to lookup\") && strings.Contains(err.Error(), \"branch\") {\n        log.Warnf(\"git ls-remote failed for %s; check `git ls-remote --heads %s` output: %v\",\n            cfg.Repo, cfg.RepoCloneURI, err)\n        return err\n    }\n    return err\n}","preventionTips":["Ensure git is installed and on PATH in every environment (CI images, devcontainers).","Configure deploy keys / SSH agent forwarding or credential helpers before running skaffold.","Validate the repoCloneURI format (https vs ssh) matches your configured credentials.","Run `git ls-remote` as a smoke test in CI pipelines before build steps.","In containers, pre-accept git host keys (ssh-keyscan) to avoid interactive verification failures."],"tags":["git","network","authentication","ls-remote"],"backgroundTag":"git-authentication-failed","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}