New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

find-gitdir

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

find-gitdir

Find .git directory with support of submodules and --separate-git-dir

latest
Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
896
-15.71%
Maintainers
1
Weekly downloads
 
Created
Source

find-gitdir

Find .git directory with support of submodules, --separate-git-dir and linked worktrees.

npm status node Test JavaScript Style Guide

Usage

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', { roam: true }) // /example/.git

API

gitdir([cwd][, options][, callback])

Yields an absolute path to a .git directory or null if not found, given working directory cwd which defaults to process.cwd(). If no callback if provided, a promise is returned. Options:

  • roam (boolean, default false): enable looking in parent directories
  • common (boolean, default false): if cwd is a linked worktree then return the gitdir of the main worktree (a.k.a. $GIT_COMMON_DIR) instead of the gitdir of the linked worktree. This can be useful if you need non-worktree files like config.

If options is a boolean, it is interpreted as options.roam for backwards compatibility.

gitdir.sync([cwd][, options])

Synchronous variant. Returns an absolute path or null.

Install

With npm do:

npm install find-gitdir

License

MIT © Vincent Weevers

Keywords

directory

FAQs

Package last updated on 17 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts