Find the closest .git containing path
https://github.com/antongolub/git-root.git
git rev-parse --show-toplevel
However, if git executable or child_process.exec are not available for some (security?) reasons, it's advisable to use tools like this one.
Inspired by pkg-dir.
.git up the dir treegitdir: </some/path.git> redirects yarn add @antongolub/git-root
import { gitRoot, gitRootSync } from '@antongolub/git-root'
// async
const gitRoot1 = await gitRoot('/optional/cwd/path/')
// sync
const gitRoot2 = gitRoot('/defaults/to/process/cwd/', true)
// sync too
const gitRoot3 = gitRoot.sync()
// `gitRootSync` is an alias for `gitRoot.sync`
const gitRoot4 = gitRootSync()