Find .git
directory with support of submodules and --separate-git-dir
.
const gitdir = require('find-gitdir')
Let's say we have a git repository at /example
and that this is our working directory. Its gitdir will commonly be at /example/.git
.
await gitdir() // /example/.git
Let's also say we have a git submodule at ./beep
. Then find-gitdir
will find a symbolic link at ./beep/.git
pointing to the gitdir ../.git/modules/beep
:
await gitdir('./beep') // /example/.git/modules/beep
By default find-gitdir
does not look in parent directories. It can be enabled:
await gitdir('./node_modules/find-gitdir') // null
await gitdir('./node_modules/find-gitdir', true) // /example/.git
Yields an absolute path to a .git
directory or null
if not found, given working directory cwd
which defaults to process.cwd()
. Set roam
to true to enable looking in parent directories. If no callback if provided, a promise is returned.
Synchronous variant. Returns an absolute path or null
.
With npm do:
npm install find-gitdir
MIT © Vincent Weevers