{"record":{"id":"4443036e90200feb","repo":"midudev/autoskills","slug":"git-ls-remote-failed-for-repo-result-stderr-trim-unknown","errorCode":null,"errorMessage":"git ls-remote failed for ${repo}: ${result.stderr.trim() || \"unknown error\"}","messagePattern":"git ls-remote failed for (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/autoskills/scripts/sync-skills.mjs","lineNumber":176,"sourceCode":"        `GitHub 403 rate limit exceeded${resetSuffix} for ${url}. Set GITHUB_TOKEN or GH_TOKEN to increase the limit.`,\n      );\n    }\n    throw new Error(`GitHub ${res.status} ${res.statusText} for ${url}`);\n  }\n  return res;\n}\n\nfunction resolveRepoHead(repo) {\n  const result = spawnSync(\n    \"git\",\n    [\"ls-remote\", \"--symref\", `https://github.com/${repo}.git`, \"HEAD\"],\n    {\n      encoding: \"utf-8\",\n      stdio: [\"ignore\", \"pipe\", \"pipe\"],\n    },\n  );\n  if (result.status !== 0) {\n    throw new Error(`git ls-remote failed for ${repo}: ${result.stderr.trim() || \"unknown error\"}`);\n  }\n\n  let defaultBranch = \"main\";\n  let sha = \"\";\n  for (const line of result.stdout.split(\"\\n\")) {\n    const symref = line.match(/^ref:\\s+refs\\/heads\\/(.+)\\s+HEAD$/);\n    if (symref) {\n      defaultBranch = symref[1];\n      continue;\n    }\n    const head = line.match(/^([0-9a-f]{40})\\s+HEAD$/i);\n    if (head) sha = head[1];\n  }\n\n  if (!sha) {\n    throw new Error(`could not resolve HEAD for ${repo}`);\n  }\n","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/midudev/autoskills/blob/0ec725320d2137253ab2e68e7ba8a072148e741a/packages/autoskills/scripts/sync-skills.mjs#L158-L194","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run `git ls-remote <repo-url>` manually to see the real git error","Check network connectivity / proxy settings (HTTP_PROXY, HTTPS_PROXY)","If the repo is private, set GITHUB_TOKEN or configure git credentials for the remote","Verify the repo exists and the URL/owner/name is spelled correctly"],"exampleFix":"// before\nawait syncSkills({ repo: \"org/skilz\" }); // typo\n// after\nawait syncSkills({ repo: \"org/skills\" }); // verify with git ls-remote first","handlingStrategy":"try-catch","validationCode":"// pre-check remote reachability before invoking the script\nimport { execSync } from \"node:child_process\";\nconst url = `https://github.com/${repo}`;\nexecSync(`git ls-remote ${url} HEAD`, { stdio: \"ignore\" }); // throws early with git's real error","typeGuard":null,"tryCatchPattern":"try {\n  await syncSkills({ repo });\n} catch (err) {\n  if (String(err.message).startsWith(\"git ls-remote failed\")) {\n    console.error(\"Remote unreachable or unauthorized:\", err.message);\n    // check network/proxy/credentials, then retry\n  } else throw err;\n}","preventionTips":["Run `git ls-remote <url> HEAD` as a smoke test before batch syncs","Keep git credential helpers configured for private repos","Set GITHUB_TOKEN for private repo access","Verify proxy env vars (HTTPS_PROXY) when behind a corporate firewall"],"tags":["git","network","remote"],"backgroundTag":"git-command-failed","analyzedSha":"0ec725320d2137253ab2e68e7ba8a072148e741a","analyzedAt":"2026-09-15T14:12:31.090Z","contentChangedAt":"2026-09-15T14:12:31.090Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}