static function fromRepository(string $path = ''): self {
    $workingDir = getcwd() ?: '.';
    if (!mb_strlen($path)) $path = $workingDir;
    chdir($path);

    $commands = (object) array_map(function($command) { return trim(`git $command`); }, [
      'author_email' => 'log -1 --pretty=format:%ae',
      'author_name' => 'log -1 --pretty=format:%aN',
      'branch' => 'rev-parse --abbrev-ref HEAD',
      'committer_email' => 'log -1 --pretty=format:%ce',
      'committer_name' => 'log -1 --pretty=format:%cN',
      'id' => 'log -1 --pretty=format:%H',
      'message' => 'log -1 --pretty=format:%s',
      'remotes' => 'remote -v'
    ]);

    $remotes = [];
    foreach (preg_split('/\r?\n/', $commands->remotes) ?: [] as $remote) {
      $parts = explode(' ', (string) preg_replace('/\s+/', ' ', $remote));
      if (!isset($remotes[$parts[0]])) $remotes[$parts[0]] = new GitRemote($parts[0], count($parts) > 1 ? $parts[1] : null);
    }

    chdir($workingDir);
    return new static(GitCommit::fromJson($commands), $commands->branch, array_values($remotes));
  }