{"record":{"id":"60bb090e5873a932","repo":"GoogleContainerTools/skaffold","slug":"failed-to-clone-repo-s-trouble-getting-default-b","errorCode":null,"errorMessage":"failed to clone repo %s: trouble getting default branch: %w","messagePattern":"failed to clone repo (.+?): trouble getting default branch: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/git/gitutil.go","lineNumber":114,"sourceCode":"\treturn base64.URLEncoding.EncodeToString(hasher.Sum(nil))[:32], nil\n}\n\nfunc syncRepo(ctx context.Context, g Config, opts config.SkaffoldOptions) (string, error) {\n\tskaffoldCacheDir, err := config.GetRemoteCacheDir(opts)\n\tr := gitCmd{Dir: skaffoldCacheDir}\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to clone repo %s: %w\", g.Repo, err)\n\t}\n\tif err := os.MkdirAll(skaffoldCacheDir, 0700); err != nil {\n\t\treturn \"\", fmt.Errorf(\n\t\t\t\"failed to clone repo %s: trouble creating cache directory: %w\", g.Repo, err)\n\t}\n\n\tref := g.Ref\n\tif ref == \"\" {\n\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","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/git/gitutil.go#L96-L132","documentation":"Thrown by syncRepo when g.Ref is empty and defaultRef(ctx, g.RepoCloneURI, g.Repo) fails to determine the remote's default branch (it runs git ls-remote against the repo). syncRepo needs a ref to clone with when none is explicitly configured; the underlying git/network error is wrapped.","triggerScenarios":"syncRepo invoked with a GitInfo whose Ref field is empty, and the git ls-remote call in defaultRef fails (network failure, bad credentials, repo not found, git binary missing).","commonSituations":"Private repo without credentials configured (ssh key or token missing); typo in the remote-sync git URL; offline CI runner; corporate proxy blocking ls-remote; repo deleted or renamed on the remote.","solutions":["Explicitly set the ref in the git sync config so defaultRef is never called (e.g. ref: main).","Run `git ls-remote <URL>` manually to reproduce and see the real error; fix credentials/network accordingly.","Configure git credentials: ssh key added to ssh-agent, or HTTPS token via credential helper / GH_TOKEN.","Verify the repo URL is reachable and correct; check proxy settings (HTTPS_PROXY) and connectivity."],"exampleFix":"// before\nsync:\n  manual: [{src: 'src/**/*.go', dest: './'}]  # repo: https://github.com/org/repo (no ref)\n// after\nsync:\n  manual: [{src: 'src/**/*.go', dest: './'}]  # repo: https://github.com/org/repo#main  (or set ref explicitly)","handlingStrategy":"validation","validationCode":"const { execSync } = require('child_process');\nfunction remoteReachable(uri) {\n  try { execSync(`git ls-remote ${uri} HEAD`, { stdio: 'pipe' }); return true; }\n  catch (e) { console.error('ls-remote failed:', e.stderr.toString()); return false; }\n}","typeGuard":"function hasExplicitRef(gitSync) {\n  return typeof gitSync.ref === 'string' && gitSync.ref.length > 0;\n}","tryCatchPattern":"try {\n  await syncRepo(g, ctx, opts);\n} catch (err) {\n  if (/trouble getting default branch/.test(err.message)) {\n    // retry once with explicit ref after connectivity check\n    g.ref = 'main';\n    return syncRepo(g, ctx, opts);\n  }\n  throw err;\n}","preventionTips":["Always pin ref in git sync config so defaultRef (ls-remote) is never needed.","Configure git credentials (ssh-agent or credential helper) in CI images before skaffold runs.","Test `git ls-remote <repo-url>` in the exact environment that runs skaffold.","Set HTTPS_PROXY/NO_PROXY correctly in proxied networks."],"tags":["git","network","authentication"],"backgroundTag":"git-remote-unreachable","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"}