Documentation for Simbo's Packages
    Preparing search index...

    Module @simbo/find-git-repository-root - v4.0.1

    Find Git Repository Root

    📦 @simbo/find-git-repository-root

    A lightweight utility for locating the root directory of a Git working tree, including linked worktrees and submodules.

    It asks Git for the top-level directory with git rev-parse --show-toplevel.

    • Detects the root directory of a Git working tree, including linked worktrees and submodules

    • Returns the canonical absolute path, with symbolic links resolved

    • Starts from a given working directory (defaults to process.cwd())

    • Async and Promise-based API

    • Fully typed with TypeScript

    Requires Node.js ^24.15.0 || >=26.0.0 and Git on the PATH.

    Install @simbo/find-git-repository-root from the npm registry:

    npm i [-D] @simbo/find-git-repository-root
    

    For a complete API reference, see the documentation.

    import { findGitRepositoryRoot } from '@simbo/find-git-repository-root';

    // Default: start from current working directory
    const root = await findGitRepositoryRoot();

    // Or specify a starting directory
    const rootFromPath = await findGitRepositoryRoot('/path/to/subdir');
    Directory Result
    Inside a repository root of the repository
    Inside a linked worktree root of the worktree
    Inside a submodule root of the submodule
    Bare repository or .git directory undefined
    Outside a repository, even with a .git folder undefined
    Missing path or file undefined
    Git cannot be started rejects (GitError)

    MIT © Simon Lepel

    findGitRepositoryRoot