Find the closest `.git` directory

readme.md

git-dir-up

Find the closest .git directory

Package Version Downloads Status Build Status: Linux Coverage Status

Useful for tools that need to know whether git is managing the things inside.

Installation

npm install --save git-dir-up

Usage

/
└── Users
    └── luftywiranda
        └── foo
            ├── .git
            └── bar
                ├── baz
                └── example.js
// example.js
const gitDirUp = require('git-dir-up');

gitDirUp(__dirname).then(filepath => {
  console.log(filepath);
  //=> '/Users/luftywiranda/foo/.git'
});

API

gitDirUp([cwd])

Returns a Promise for either the filepath or null if it couldn't be found.

cwd

Type: string
Default: process.cwd()

Directory to start from.

Related

  • git-root-dir – Find the root directory of a git repository
  • pkg-up – Find the closest package.json file

License

MIT © Lufty Wiranda