๐Ÿ“ฆ antongolub / git-root

Find the closest .git containing path

โ˜… 1 stars โ‘‚ 1 forks ๐Ÿ‘ 1 watching โš–๏ธ MIT License
gitutil
๐Ÿ“ฅ Clone https://github.com/antongolub/git-root.git
HTTPS git clone https://github.com/antongolub/git-root.git
SSH git clone git@github.com:antongolub/git-root.git
CLI gh repo clone antongolub/git-root
renovate[bot] renovate[bot] chore(deps): update dependency typedoc to ^0.27.0 cb21d9e 1 years ago ๐Ÿ“ History
๐Ÿ“‚ master View all commits โ†’
๐Ÿ“ .github
๐Ÿ“ src
๐Ÿ“„ .gitignore
๐Ÿ“„ CHANGELOG.md
๐Ÿ“„ LICENSE
๐Ÿ“„ package.json
๐Ÿ“„ README.md
๐Ÿ“„ renovate.json
๐Ÿ“„ tsconfig.json
๐Ÿ“„ yarn.lock
๐Ÿ“„ README.md

@antongolub/git-root

Find the closest .git containing path โ€” the git root.

CI Maintainability Test Coverage npm (scoped)

Motivation

It's known for certain the best way to find git root:
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.

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

yarn add @antongolub/git-root

Usage

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

License

MIT