# @antongolub/git-root

> Find the closest .git containing path

Latest version **1.5.14** (published 2024-07-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install @antongolub/git-root
pnpm add @antongolub/git-root
yarn add @antongolub/git-root
bun add @antongolub/git-root
```

## Health

**Score 50/100 (C)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.5.14 |
| Published | 2024-07-06 |
| First published | 2021-01-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 1 |
| Author | Anton Golub |
| Maintainers | antongolub |
| Keywords | git, root, git root, git dir |

## Links

- npm: https://www.npmjs.com/package/@antongolub/git-root
- Repository: https://github.com/antongolub/git-root
- Homepage: https://github.com/antongolub/git-root/#readme
- Issues: https://github.com/antongolub/git-root/issues
- npm.io page: https://npm.io/package/@antongolub/git-root

## Recent versions

- 1.5.14 (latest) — 2024-07-06
- 1.5.13 — 2023-06-27
- 1.5.12 — 2023-06-01
- 1.5.11 — 2023-05-29
- 1.5.10 — 2023-02-16
- 1.5.9 — 2023-02-16
- 1.5.8 — 2022-11-21
- 1.5.7 — 2022-05-24
- 1.5.6 — 2021-06-10
- 1.5.5 — 2021-05-25
- 1.5.4 — 2021-05-03
- 1.5.3 — 2021-03-28
- 1.5.2 — 2021-03-08
- 1.5.1 — 2021-02-07
- 1.5.0 — 2021-02-06
- … 1 more at https://npm.io/package/@antongolub/git-root/versions

## README

# @antongolub/git-root
Find the closest .git containing path — the git root.

[![CI](https://github.com/antongolub/git-root/workflows/CI/badge.svg)](https://github.com/antongolub/git-root/actions)
[![Maintainability](https://api.codeclimate.com/v1/badges/77d281e69a451680e1d1/maintainability)](https://codeclimate.com/github/antongolub/git-root/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/77d281e69a451680e1d1/test_coverage)](https://codeclimate.com/github/antongolub/git-root/test_coverage)
[![npm (scoped)](https://img.shields.io/npm/v/@antongolub/git-root)](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: </some/path.git>` 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)

---
_Source: https://npm.io/package/@antongolub/git-root · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
