Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@igorskyflyer/is-git-repo

igorskyflyer98MIT1.1.0TypeScript support: included

🐸 Checks if a directory is a local Git repository. 🕶️

directory, folder, git, svc, check, local, fs, repo, repository, git, github, versioning, igorskyflyer

readme

Icon of Is Git Repo

Is Git Repo


🐸 Checks if a directory is a local Git repository. 🕶️



📃 Table of Contents



🤖 Features

  • ⚡ Async & sync checks — verify Git repo status your way
  • 📂 Custom directory — point to any folder, not just the current one
  • 🛡 Input validation — catches invalid or missing paths early
  • 🚫 Existence check — errors if the directory doesn’t exist
  • 🖥 Direct Git command — uses git rev-parse for accurate detection
  • ✅ Boolean result — simple true/false output for easy logic flow
  • 🧩 Error-safe — gracefully handles Git errors without crashing
  • 🪶 Lightweight dependency — minimal overhead, fast execution


⚠️ WARNING

This module requires that the git executable is installed and available in the system path.

If not, it needs to be installed first.



🕵🏼 Usage

Install it by executing any of the following, depending on your preferred package manager:

pnpm add @igorskyflyer/is-git-repo
yarn add @igorskyflyer/is-git-repo
npm i @igorskyflyer/is-git-repo


🤹🏼 API

isGitRepo(options?): Promise<boolean>

Asynchronously checks if a local directory is a Git repository.

options - Optional object with options:

  • directory - Sets the current working directory, otherwise the current directory will be used instead.

Will throw an error if the passed directory is not valid or does not exist.

Returns a Boolean indicating whether provided local directory is a Git repository.


isGitRepoSync(options?): boolean

Synchronously checks if a local directory is a Git repository.

options - Optional object with options:

  • directory - Sets the current working directory, otherwise the current directory will be used instead.

Will throw an error if the passed directory is not valid or does not exist.

Returns a Boolean indicating whether provided local directory is a Git repository.



🗒️ Examples

example.ts

import { isGitRepoSync } from '@igorskyflyer/is-git-repo'

console.log(isGitRepoSync({ directory: '../my-git-project' })) // true


📝 Changelog

📑 The changelog is available here, CHANGELOG.md.



🪪 License

Licensed under the MIT license which is available here, MIT license.



💖 Support

I work hard for every project, including this one and your support means a lot to me!
Consider buying me a coffee. ☕

Donate to igorskyflyer

Thank you for supporting my efforts! 🙏😊


@igorskyflyer/vscode-folderpicker

✨ Provides a custom Folder Picker API + UI for Visual Studio Code. 🎨


@igorskyflyer/git-repo-url

🌐 Gets the origin URL a local Git repository. 🗺️


@igorskyflyer/is-rootdir

🔼 Provides a way to check if the given path is the root drive/directory. ⛔


@igorskyflyer/str-is-in

🧵 Provides ways of checking whether a String is present in an Array of Strings using custom Comparators. 🔍


@igorskyflyer/chars-in-string

🪐 Provides ways of testing whether an array of chars is present inside a given String. ☄




👨🏻‍💻 Author

Created by Igor Dimitrijević (@igorskyflyer).

changelog

📒 Changelog

of @igorskyflyer/is-git-repo


v1.1.0 (29-Aug-2025)

  • 💻 dev: upgrade Node to >= v22
  • 💻 dev: upgrade dependencies

v1.0.2 (02-Aug-2024)

  • 📜 docs: fix docs


v1.0.1 (29-Jul-2024)

  • 📜 docs: fix docs


v1.0.0 (29-Jul-2024)

  • 🚀 launch: initial release 🎉