yarnpkg/yarn · error · Error

Unable to find SHA for git HEAD

Error message

Unable to find SHA for git HEAD

What it means

Error "Unable to find SHA for git HEAD" thrown in yarnpkg/yarn.

Source

Thrown at src/util/git.js:448

  }

  /**
   * Resolves the default branch of a remote repository (not always "master")
   */

  async resolveDefaultBranch(): Promise<ResolvedSha> {
    const isLocal = this.gitUrl.protocol === FILE_PROTOCOL;

    try {
      let stdout;
      if (isLocal) {
        stdout = await spawnGit(['show-ref', 'HEAD'], {cwd: this.gitUrl.repository});
        const refs = parseRefs(stdout);
        const sha = refs.values().next().value;
        if (sha) {
          return {sha, ref: undefined};
        } else {
          throw new Error('Unable to find SHA for git HEAD');
        }
      } else {
        stdout = await spawnGit(['ls-remote', '--symref', this.gitUrl.repository, 'HEAD']);
        const lines = stdout.split('\n').filter(validRef);
        const [, ref] = lines[0].split(/\s+/);
        const [sha] = lines[1].split(/\s+/);
        return {sha, ref};
      }
    } catch (err) {
      handleSpawnError(err);
      // older versions of git don't support "--symref"
      const stdout = await spawnGit(['ls-remote', this.gitUrl.repository, 'HEAD']);
      const lines = stdout.split('\n').filter(validRef);
      const [sha] = lines[0].split(/\s+/);
      return {sha, ref: undefined};
    }
  }

View on GitHub (pinned to c2dda503f3)

Solutions

  1. 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.
  2. Verify the path in the file: dependency points to the intended git repository and that `git show-ref HEAD` succeeds there.

Example fix

cd <local-repo> && git commit --allow-empty -m init && yarn install

When it happens

Trigger: Yarn cannot resolve the SHA of the git HEAD reference when inspecting a git dependency in src/util/git.js.

Common situations: Occurs with a corrupted or bare git clone, an empty repository with no commits, or when the HEAD ref is detached or missing.


AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13). Data as JSON: /api/errors/a8fd030326050346. Report an issue: GitHub.