Skip to main content

Prerequisites

Before installing useGit, ensure you have the following:
  • Node.js 18 or higher
  • Git installed on your system
useGit is a Node.js wrapper around Git commands, so Git must be installed and accessible in your PATH.

Package Installation

Install useGit using your preferred package manager:
npm install use-git

Verify Installation

After installation, verify that useGit can detect your Git installation:
import { git } from 'use-git';

const isInstalled = await git.isGitInstalled();
console.log('Git installed:', isInstalled); // true

const version = await git.version();
console.log('Git version:', version); // e.g., "2.39.0"

TypeScript Support

useGit is written in TypeScript and includes full type definitions out of the box. No additional @types packages are needed.

TypeScript Configuration

For the best experience, ensure your tsconfig.json includes:
tsconfig.json
{
  "compilerOptions": {
    "moduleResolution": "node",
    "esModuleInterop": true,
    "strict": true,
    "target": "ES2020",
    "module": "ESNext"
  }
}

Import Styles

useGit supports both ES modules and CommonJS:
import { git, createGit } from 'use-git';

// Use the default git instance
await git.init();

// Or create a custom instance
const myGit = createGit({ cwd: './my-repo' });
await myGit.init();

Package Exports

The package provides the following exports:
  • git - Default Git instance with current working directory
  • createGit(options) - Factory function to create custom Git instances
  • All Git operation functions can be imported individually if needed

Next Steps

Quick Start Guide

Learn how to use useGit with a practical example

Build docs developers (and LLMs) love