{"record":{"id":"ffea9ad54cc5c7ed","repo":"GoogleContainerTools/skaffold","slug":"failed-to-clone-repo-w","errorCode":null,"errorMessage":"failed to clone repo: %w","messagePattern":"failed to clone repo: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/git/gitutil.go","lineNumber":130,"sourceCode":"\t\tref, err = defaultRef(ctx, g.RepoCloneURI, g.Repo)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to clone repo %s: trouble getting default branch: %w\", g.Repo, err)\n\t\t}\n\t}\n\n\thash, err := getRepoDir(g)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to clone git repo: unable to create directory name: %w\", err)\n\t}\n\trepoCacheDir := filepath.Join(skaffoldCacheDir, hash)\n\tif _, err := os.Stat(repoCacheDir); os.IsNotExist(err) {\n\t\tif opts.SyncRemoteCache.CloneDisabled() {\n\t\t\treturn \"\", SyncDisabledErr(g, repoCacheDir)\n\t\t}\n\t\tif _, err := r.Run(ctx, \"clone\", g.RepoCloneURI, fmt.Sprintf(\"./%s\", hash), \"--branch\", ref, \"--depth\", \"1\"); err != nil {\n\t\t\tif strings.Contains(err.Error(), \"Could not find remote branch\") {\n\t\t\t\tif _, err := r.Run(ctx, \"clone\", g.RepoCloneURI, fmt.Sprintf(\"./%s\", hash), \"--depth\", \"1\"); err != nil {\n\t\t\t\t\treturn \"\", fmt.Errorf(\"failed to clone repo: %w\", err)\n\t\t\t\t}\n\n\t\t\t\tr.Dir = repoCacheDir\n\t\t\t\tif _, err := r.Run(ctx, \"checkout\", ref); err != nil {\n\t\t\t\t\tif rmErr := os.RemoveAll(repoCacheDir); rmErr != nil {\n\t\t\t\t\t\terr = fmt.Errorf(\"failed to remove repo cache dir: %w\", rmErr)\n\t\t\t\t\t}\n\n\t\t\t\t\treturn \"\", fmt.Errorf(\"failed to checkout commit: %w\", err)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn \"\", fmt.Errorf(\"failed to clone repo: %w\", err)\n\t\t\t}\n\t\t}\n\t} else {\n\t\tr.Dir = repoCacheDir\n\t\t// check remote is defined\n\t\tif remotes, err := r.Run(ctx, \"remote\", \"-v\"); err != nil {","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/git/gitutil.go#L112-L148","documentation":"Thrown by syncRepo when the initial `git clone <uri> ./<hash> --branch <ref> --depth 1` fails with 'Could not find remote branch', and the fallback `git clone <uri> ./<hash> --depth 1` (without --branch) also fails. This means the repo could not be cloned at all on the second attempt — a hard clone failure, not a missing branch. The git error is wrapped.","triggerScenarios":"First clone with --branch <ref> reports the ref missing, then the ref-less fallback clone also errors: invalid URL, auth rejected, network failure, or repo truly absent.","commonSituations":"Wrong or typo'd repo URL; cloning a private repo without credentials; the fallback clone failing due to the same auth/network problem that caused the branch lookup to fail; empty repository on the remote (no branches at all).","solutions":["Run `git clone <URI>` manually in the same environment to surface the raw git error.","Fix credentials: add the SSH key to ssh-agent or configure an HTTPS credential helper/token for the remote.","Correct the repo URL in the skaffold git sync configuration.","Confirm the remote repo exists and has at least one branch (empty repos cannot be cloned)."],"exampleFix":"// before\nrepo: https://github.com/org/wrong-repo-name\n// after\nrepo: https://github.com/org/correct-repo","handlingStrategy":"try-catch","validationCode":"const { execSync } = require('child_process');\nfunction canClone(uri) {\n  try { execSync(`git ls-remote ${uri}`, { stdio: 'pipe' }); return true; }\n  catch (e) { console.error(e.stderr.toString()); return false; }\n}\nif (!canClone(repoUri)) throw new Error(`precheck failed: cannot access ${repoUri}`);","typeGuard":"null","tryCatchPattern":"try {\n  await syncRepo(g, ctx, opts);\n} catch (err) {\n  if (/failed to clone repo:/.test(err.message)) {\n    // surface underlying git stderr; check creds/url before retrying\n    console.error('clone failed:', err.cause ?? err);\n    throw new Error(`Fix git credentials or repo URL for ${g.repo}: ${err.message}`);\n  }\n  throw err;\n}","preventionTips":["Pre-validate repo URL with git ls-remote before running skaffold.","Ensure deploy keys/tokens are present in CI images.","Never configure an empty repo as the sync source (clone needs at least one branch).","Clear partial cache dirs after failures to avoid poisoned state."],"tags":["git","network","clone"],"backgroundTag":"git-clone-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"}