https://github.com/luftywiranda13/git-root-dir
Find the root directory of a `git` repository
https://github.com/luftywiranda13/git-root-dir
Last synced: about 1 year ago
JSON representation
Find the root directory of a `git` repository
- Host: GitHub
- URL: https://github.com/luftywiranda13/git-root-dir
- Owner: luftywiranda13
- License: mit
- Created: 2018-01-12T12:52:16.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-06-03T09:19:30.000Z (about 6 years ago)
- Last Synced: 2025-03-25T21:12:30.283Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 92.8 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# git-root-dir
> Find the root directory of a `git` repository
[](https://www.npmjs.com/package/git-root-dir)
[](https://npm-stat.com/charts.html?package=git-root-dir&from=2016-04-01)
[](https://travis-ci.org/luftywiranda13/git-root-dir)
[](https://codecov.io/gh/luftywiranda13/git-root-dir)
Useful for tools that need to know whether `git` is managing the things inside.
## Installation
```sh
npm install --save git-root-dir
```
## Usage
```sh
/
└── Users
└── luftywiranda
└── foo
├── .git
└── bar
├── baz
└── example.js
```
```js
// example.js
const gitRootDir = require('git-root-dir');
gitRootDir(__dirname).then(rootDir => {
console.log(rootDir);
//=> '/Users/luftywiranda/foo'
});
```
## API
### gitRootDir([cwd])
Returns a `Promise` for either the repository root path or `null` if it couldn't be found.
#### cwd
Type: `string`
Default: `process.cwd()`
Directory to start from.
## Related
* [git-dir-up](https://github.com/luftywiranda13/git-dir-up) – Find the closest `.git` directory
* [pkg-dir](https://github.com/sindresorhus/pkg-dir) – Find the root directory of a Node.js project or npm package
## License
MIT © [Lufty Wiranda](https://www.luftywiranda.com)