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

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

    Is Git Repository Root

    📦 @simbo/is-git-repository-root

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

    It asks Git for the top-level directory with git rev-parse --show-toplevel and compares it with the given directory after resolving symbolic links in both paths.

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

    • Defaults to checking the current working directory

    • Async and Promise-based API

    • Fully typed with TypeScript

    • Zero dependencies (besides other @simbo/* packages)

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

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

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

    For a complete API reference, see the documentation.

    import { isGitRepositoryRoot } from '@simbo/is-git-repository-root';

    if (await isGitRepositoryRoot()) {
    console.log('This is a Git repository root.');
    }

    if (await isGitRepositoryRoot('/path/to/dir')) {
    console.log('That directory is a Git repository root.');
    }
    Directory Result
    Root of a repository, worktree or submodule true
    Symbolic link to such a root true
    Subdirectory of a working tree false
    Bare repository or .git directory false
    Outside a repository, even with a .git folder false
    Missing path or file false
    Git cannot be started rejects (GitError)

    MIT © Simon Lepel

    isGitRepositoryRoot