GoogleContainerTools/skaffold · error

failed to clone repo %s: trouble checking repository remote;

Error message

failed to clone repo %s: trouble checking repository remote; run 'git clone <REPO>; stat <DIR/SUBDIR>' to verify credentials: %w

What it means

Thrown by syncRepo when an existing cached clone is present but `git remote -v` fails inside it. syncRepo treats this as a corrupted or inaccessible cache clone and suggests verifying credentials, because usually the cache dir is unreadable or git can't operate there (dubious ownership, permissions, or corruption).

Source

Thrown at pkg/skaffold/git/gitutil.go:149

				}

				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 {
			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)

View on GitHub (pinned to a1189de023)

Solutions

  1. Clear the cache: rm -rf <remote-cache-dir>/<hash> and let skaffold re-clone from scratch.
  2. If it's a git ownership issue, either chown the dir to the current user or add `git config --global --add safe.directory <path>`.
  3. Fix directory permissions so the current user can read .git inside the cached clone.
  4. Ensure the cache volume is mounted read-write wherever skaffold runs.

Example fix

// before
# cache owned by root, running as user -> git refuses
// after
sudo chown -R $(whoami) ~/.skaffold/gitcache
# or
git config --global --add safe.directory '*'
Defensive patterns

Strategy: retry

Validate before calling

const { execSync } = require('child_process');
function cachedCloneUsable(dir) {
  try {
    const out = execSync(`git -C ${dir} remote -v`, { encoding: 'utf8' });
    return out.trim().length > 0;
  } catch (e) {
    // typical fix: dubious ownership
    execSync(`git config --global --add safe.directory ${dir}`, { stdio: 'pipe' });
    try { return execSync(`git -C ${dir} remote -v`, { encoding: 'utf8' }).trim().length > 0; }
    catch { return false; }
  }
}

Type guard

null

Try / catch

try {
  await syncRepo(g, ctx, opts);
} catch (err) {
  if (/trouble checking repository remote/.test(err.message)) {
    // nuke corrupted cache entry and retry fresh
    fs.rmSync(path.join(cacheDir, hashFor(g)), { recursive: true, force: true });
    return syncRepo(g, ctx, opts);
  }
  throw err;
}

Prevention

When it happens

Trigger: repoCacheDir already exists (os.Stat succeeded) and `git remote -v` run with Dir=repoCacheDir returns a non-zero exit: not a git repo, permission denied, or git 'dubious ownership' safe.directory rejection.

Common situations: Cache dir populated by a different user (CI ran as root, dev runs as user) triggering git's safe.directory error; partial cache dir missing .git; cache dir on a volume that lost permissions; skaffold cache mounted read-only.

Related errors


AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05). Data as JSON: /api/errors/d268a779c8598e6b. Report an issue: GitHub.