midudev/autoskills · error · Error

git ls-remote failed for

Error message

git ls-remote failed for ${repo}: ${result.stderr.trim() || "unknown error"}

What it means

resolveRepoHead runs `git ls-remote` against a GitHub repo to find its default branch and HEAD SHA. When git exits non-zero (network failure, auth rejection, bad remote URL), the script throws this error including the repo name and git's stderr. It is the script's way of surfacing git's own diagnostics for the remote-inspection step.

Solutions

  1. Run `git ls-remote <repo-url>` manually to see the real git error
  2. Check network connectivity / proxy settings (HTTP_PROXY, HTTPS_PROXY)
  3. If the repo is private, set GITHUB_TOKEN or configure git credentials for the remote
  4. Verify the repo exists and the URL/owner/name is spelled correctly

Example fix

// before
await syncSkills({ repo: "org/skilz" }); // typo
// after
await syncSkills({ repo: "org/skills" }); // verify with git ls-remote first
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check remote reachability before invoking the script
import { execSync } from "node:child_process";
const url = `https://github.com/${repo}`;
execSync(`git ls-remote ${url} HEAD`, { stdio: "ignore" }); // throws early with git's real error

Try / catch

try {
  await syncSkills({ repo });
} catch (err) {
  if (String(err.message).startsWith("git ls-remote failed")) {
    console.error("Remote unreachable or unauthorized:", err.message);
    // check network/proxy/credentials, then retry
  } else throw err;
}

Prevention

When it happens

Trigger: spawnSync("git", ["ls-remote", ...]) returns status !== 0 for a repo — e.g. the remote URL is wrong, the repo is private and credentials are missing, DNS/network is down, or a proxy blocks the connection.

Common situations: Developer runs sync-skills offline or behind a corporate proxy; repo renamed/deleted on GitHub so ls-remote gets 'Repository not found'; SSH vs HTTPS remote mismatch; missing GITHUB_TOKEN for a private repo.

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


AI-assisted analysis of midudev/autoskills@0ec725320d (2026-09-15). Data as JSON: /api/errors/4443036e90200feb. Report an issue: GitHub.

Appendix: source

Thrown at packages/autoskills/scripts/sync-skills.mjs:176

        `GitHub 403 rate limit exceeded${resetSuffix} for ${url}. Set GITHUB_TOKEN or GH_TOKEN to increase the limit.`,
      );
    }
    throw new Error(`GitHub ${res.status} ${res.statusText} for ${url}`);
  }
  return res;
}

function resolveRepoHead(repo) {
  const result = spawnSync(
    "git",
    ["ls-remote", "--symref", `https://github.com/${repo}.git`, "HEAD"],
    {
      encoding: "utf-8",
      stdio: ["ignore", "pipe", "pipe"],
    },
  );
  if (result.status !== 0) {
    throw new Error(`git ls-remote failed for ${repo}: ${result.stderr.trim() || "unknown error"}`);
  }

  let defaultBranch = "main";
  let sha = "";
  for (const line of result.stdout.split("\n")) {
    const symref = line.match(/^ref:\s+refs\/heads\/(.+)\s+HEAD$/);
    if (symref) {
      defaultBranch = symref[1];
      continue;
    }
    const head = line.match(/^([0-9a-f]{40})\s+HEAD$/i);
    if (head) sha = head[1];
  }

  if (!sha) {
    throw new Error(`could not resolve HEAD for ${repo}`);
  }

View on GitHub (pinned to 0ec725320d)