GoogleContainerTools/skaffold · error
failed to clone repo %s: unable to find any matching refs %s
Error message
failed to clone repo %s: unable to find any matching refs %s; run 'git clone <REPO>; stat <DIR/SUBDIR>' to verify credentials: %w
What it means
Thrown by syncRepo when updating an existing cached clone: `git fetch origin <ref>` fails, meaning the requested ref could not be fetched from origin. The message 'unable to find any matching refs' plus the credentials hint reflect the most common cause — the ref doesn't exist on the remote or access is denied. The raw git error is wrapped via %w.
Source
Thrown at pkg/skaffold/git/gitutil.go:167
return "", fmt.Errorf("failed to clone repo %s: trouble checking repository remote; run 'git clone <REPO>; stat <DIR/SUBDIR>' to verify credentials: %w", g.Repo, err)
} else if len(remotes) == 0 {
return "", fmt.Errorf("failed to clone repo %s: remote not set for existing clone", g.Repo)
}
// if sync property is false, then skip fetching latest from remote and resetting the branch.
if g.Sync != nil && !*g.Sync {
return repoCacheDir, nil
}
// if sync is turned off via flag `--sync-remote-cache`, then skip fetching latest from remote and resetting the branch.
if opts.SyncRemoteCache.FetchDisabled() {
return repoCacheDir, nil
}
tryUpdateRemoteOriginFetchURL(ctx, r, g.RepoCloneURI)
if _, err = r.Run(ctx, "fetch", "origin", ref); err != nil {
return "", fmt.Errorf("failed to clone repo %s: unable to find any matching refs %s; run 'git clone <REPO>; stat <DIR/SUBDIR>' to verify credentials: %w", g.Repo, ref, err)
}
// Sync option is either nil or true, so we are resetting the repo
if _, err := r.Run(ctx, "reset", "--hard", fmt.Sprintf("origin/%s", ref)); err != nil {
return "", fmt.Errorf("failed to clone repo %s: trouble resetting branch to origin/%s; run 'git clone <REPO>; stat <DIR/SUBDIR>' to verify credentials: %w", g.Repo, ref, err)
}
}
return repoCacheDir, nil
}
// gitCmd runs git commands in a git repo.
type gitCmd struct {
// Dir is the directory the commands are run in.
Dir string
}
// Run runs a git command.
// Omit the 'git' part of the command.View on GitHub (pinned to a1189de023)
Solutions
- Verify the ref exists and is reachable: git ls-remote <RepoCloneURI> <ref>; correct the ref in config if renamed.
- Refresh credentials (ssh key, PAT/expired token) so fetch origin can authenticate.
- Delete the cached clone and let skaffold re-clone: rm -rf <remote-cache-dir>/<hash>.
- Check network/proxy settings; run git fetch origin <ref> inside the cached dir manually to see the raw error.
Example fix
// before repo: https://github.com/org/repo#release-1.0 # branch deleted upstream // after repo: https://github.com/org/repo#release-1.1
Defensive patterns
Strategy: retry
Validate before calling
const { execSync } = require('child_process');
function refFetchable(uri, ref) {
try {
execSync(`git ls-remote --exit-code ${uri} ${ref}`, { stdio: 'pipe' });
return true;
} catch (e) {
console.error('ref not fetchable:', e.stderr?.toString() ?? e.message);
return false;
}
} Type guard
null
Try / catch
try {
await syncRepo(g, ctx, opts);
} catch (err) {
if (/unable to find any matching refs/.test(err.message)) {
// transient network or expired creds: refresh creds and retry with backoff
await sleep(3000);
return syncRepo(g, ctx, opts);
}
throw err;
} Prevention
- git ls-remote --exit-code <uri> <ref> in preflight to confirm the ref exists and is accessible.
- Rotate tokens/keys before expiry in long-lived CI runners.
- Delete the cached clone after any fetch failure so the next run starts clean.
- Watch for upstream branch deletions/renames and update sync configs accordingly.
When it happens
Trigger: Cached clone exists, sync is enabled, and `git fetch origin <ref>` returns non-zero: unknown ref name, fetch URL pointing to a repo the user can't access, or network failure.
Common situations: Config ref renamed/deleted upstream (branch protection deleted branch); credentials expired for a private repo; offline or proxied environment; tryUpdateRemoteOriginFetchURL set origin to a URI the current environment can't authenticate against.
Related errors
- failed to lookup %s branch for repo %s: %w
- failed to clone repo %s: trouble getting default branch: %w
- CONFIG_REMOTE_REPO_CACHE_NOT_FOUND_ERR
- getting tags: %w
- DEPLOY_GET_CLOUD_RUN_CLIENT_ERR
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/805de16e2df89517.
Report an issue: GitHub.