GoogleContainerTools/skaffold · error
failed to clone repo: %w
Error message
failed to clone repo: %w
What it means
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.
Source
Thrown at pkg/skaffold/git/gitutil.go:130
ref, err = defaultRef(ctx, g.RepoCloneURI, g.Repo)
if err != nil {
return "", fmt.Errorf("failed to clone repo %s: trouble getting default branch: %w", g.Repo, err)
}
}
hash, err := getRepoDir(g)
if err != nil {
return "", fmt.Errorf("failed to clone git repo: unable to create directory name: %w", err)
}
repoCacheDir := filepath.Join(skaffoldCacheDir, hash)
if _, err := os.Stat(repoCacheDir); os.IsNotExist(err) {
if opts.SyncRemoteCache.CloneDisabled() {
return "", SyncDisabledErr(g, repoCacheDir)
}
if _, err := r.Run(ctx, "clone", g.RepoCloneURI, fmt.Sprintf("./%s", hash), "--branch", ref, "--depth", "1"); err != nil {
if strings.Contains(err.Error(), "Could not find remote branch") {
if _, err := r.Run(ctx, "clone", g.RepoCloneURI, fmt.Sprintf("./%s", hash), "--depth", "1"); err != nil {
return "", fmt.Errorf("failed to clone repo: %w", err)
}
r.Dir = repoCacheDir
if _, err := r.Run(ctx, "checkout", ref); err != nil {
if rmErr := os.RemoveAll(repoCacheDir); rmErr != nil {
err = fmt.Errorf("failed to remove repo cache dir: %w", rmErr)
}
return "", fmt.Errorf("failed to checkout commit: %w", err)
}
} else {
return "", fmt.Errorf("failed to clone repo: %w", err)
}
}
} else {
r.Dir = repoCacheDir
// check remote is defined
if remotes, err := r.Run(ctx, "remote", "-v"); err != nil {View on GitHub (pinned to a1189de023)
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).
Example fix
// before repo: https://github.com/org/wrong-repo-name // after repo: https://github.com/org/correct-repo
Defensive patterns
Strategy: try-catch
Validate before calling
const { execSync } = require('child_process');
function canClone(uri) {
try { execSync(`git ls-remote ${uri}`, { stdio: 'pipe' }); return true; }
catch (e) { console.error(e.stderr.toString()); return false; }
}
if (!canClone(repoUri)) throw new Error(`precheck failed: cannot access ${repoUri}`); Type guard
null
Try / catch
try {
await syncRepo(g, ctx, opts);
} catch (err) {
if (/failed to clone repo:/.test(err.message)) {
// surface underlying git stderr; check creds/url before retrying
console.error('clone failed:', err.cause ?? err);
throw new Error(`Fix git credentials or repo URL for ${g.repo}: ${err.message}`);
}
throw err;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- caching remote dependency %s: %w
- failed to lookup %s branch for repo %s: %w
- failed to clone repo %s: trouble getting default branch: %w
- failed to clone repo %s: trouble resetting branch to origin/
- CONFIG_REMOTE_REPO_CACHE_NOT_FOUND_ERR
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/ffea9ad54cc5c7ed.
Report an issue: GitHub.