https://github.com/antongolub/git-root
Find the closest .git containing path
https://github.com/antongolub/git-root
git util
Last synced: about 1 year ago
JSON representation
Find the closest .git containing path
- Host: GitHub
- URL: https://github.com/antongolub/git-root
- Owner: antongolub
- License: mit
- Created: 2021-01-31T16:08:53.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-03-15T17:32:13.000Z (over 1 year ago)
- Last Synced: 2025-04-16T03:55:52.634Z (about 1 year ago)
- Topics: git, util
- Language: TypeScript
- Homepage:
- Size: 7.22 MB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @antongolub/git-root
Find the closest .git containing path — the git root.
[](https://github.com/antongolub/git-root/actions)
[](https://codeclimate.com/github/antongolub/git-root/maintainability)
[](https://codeclimate.com/github/antongolub/git-root/test_coverage)
[](https://www.npmjs.com/package/@antongolub/git-root)
## Motivation
It's known for certain the best way to find git root:
```shell
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](https://github.com/sindresorhus/pkg-dir).
## Features
* Searches for `.git` up the dir tree
* Handles `gitdir: ` redirects
* TS and Flow typings out of box
* Sync/async methods
## Install
```shell
yarn add @antongolub/git-root
```
## Usage
```ts
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()
```
## Alternatives
* [find-git-root](https://github.com/banyudu/find-git-root)
* [git-root](https://github.com/JPeer264/node-git-root)
* [git-toplevel](https://github.com/royriojas/git-toplevel)
* [git-root-path](https://github.com/VishnuTSuresh/git-root-path)
## License
[MIT](./LICENSE)