{"record":{"id":"a8fd030326050346","repo":"yarnpkg/yarn","slug":"unable-to-find-sha-for-git-head","errorCode":null,"errorMessage":"Unable to find SHA for git HEAD","messagePattern":"Unable to find SHA for git HEAD","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/util/git.js","lineNumber":448,"sourceCode":"  }\n\n  /**\n   * Resolves the default branch of a remote repository (not always \"master\")\n   */\n\n  async resolveDefaultBranch(): Promise<ResolvedSha> {\n    const isLocal = this.gitUrl.protocol === FILE_PROTOCOL;\n\n    try {\n      let stdout;\n      if (isLocal) {\n        stdout = await spawnGit(['show-ref', 'HEAD'], {cwd: this.gitUrl.repository});\n        const refs = parseRefs(stdout);\n        const sha = refs.values().next().value;\n        if (sha) {\n          return {sha, ref: undefined};\n        } else {\n          throw new Error('Unable to find SHA for git HEAD');\n        }\n      } else {\n        stdout = await spawnGit(['ls-remote', '--symref', this.gitUrl.repository, 'HEAD']);\n        const lines = stdout.split('\\n').filter(validRef);\n        const [, ref] = lines[0].split(/\\s+/);\n        const [sha] = lines[1].split(/\\s+/);\n        return {sha, ref};\n      }\n    } catch (err) {\n      handleSpawnError(err);\n      // older versions of git don't support \"--symref\"\n      const stdout = await spawnGit(['ls-remote', this.gitUrl.repository, 'HEAD']);\n      const lines = stdout.split('\\n').filter(validRef);\n      const [sha] = lines[0].split(/\\s+/);\n      return {sha, ref: undefined};\n    }\n  }\n","sourceCodeStart":430,"sourceCodeEnd":466,"githubUrl":"https://github.com/yarnpkg/yarn/blob/c2dda503f3759b5be5f0e24ecd9cf5c97a540147/src/util/git.js#L430-L466","documentation":"Error \"Unable to find SHA for git HEAD\" thrown in yarnpkg/yarn.","triggerScenarios":"Yarn cannot resolve the SHA of the git HEAD reference when inspecting a git dependency in src/util/git.js.","commonSituations":"Occurs with a corrupted or bare git clone, an empty repository with no commits, or when the HEAD ref is detached or missing.","solutions":["The local git repository referenced by the file: dependency has a HEAD that does not resolve to a commit (e.g. an empty repository or detached/unborn HEAD). Create an initial commit in that repository, then retry.","Verify the path in the file: dependency points to the intended git repository and that `git show-ref HEAD` succeeds there."],"exampleFix":"cd <local-repo> && git commit --allow-empty -m init && yarn install","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"c2dda503f3759b5be5f0e24ecd9cf5c97a540147","analyzedAt":"2026-08-13T04:17:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}