Skip to content

Git

Defined in: src/core/git.ts:359

Main Git interface for repository-agnostic operations

Provides type-safe wrappers for Git commands that don’t require a repository context. Each method corresponds to a specific Git CLI command.

Properties

config

config: GlobalConfigOperations

Defined in: src/core/git.ts:467

Global config operations

Wraps: git config --global subcommands

Operates on ~/.gitconfig (user-level configuration). For repository-level config, use repo.config instead.


lfs

lfs: GlobalLfsOperations

Defined in: src/core/git.ts:477

Global LFS operations

Wraps: git lfs subcommands for user-level configuration

Operates on ~/.gitconfig (user-level) or /etc/gitconfig (system-level). For repository-level LFS operations, use repo.lfs instead.

Methods

clone()

Call Signature

clone(url, path, opts): Promise<BareRepo>

Defined in: src/core/git.ts:418

Clone a repository

Wraps: git clone <url> <path>

The return type depends on the bare or mirror option:

  • { bare: true } or { mirror: true }BareRepo
  • Otherwise → WorktreeRepo
Parameters
url

string

path

string

opts

CloneOpts & object & ExecOpts

Returns

Promise<BareRepo>

Call Signature

clone(url, path, opts): Promise<BareRepo>

Defined in: src/core/git.ts:419

Parameters
url

string

path

string

opts

CloneOpts & object & ExecOpts

Returns

Promise<BareRepo>

Call Signature

clone(url, path, opts?): Promise<WorktreeRepo>

Defined in: src/core/git.ts:424

Parameters
url

string

path

string

opts?

CloneOpts & ExecOpts

Returns

Promise<WorktreeRepo>


init()

Call Signature

init(path, opts): Promise<BareRepo>

Defined in: src/core/git.ts:435

Initialize a new repository

Wraps: git init <path>

The return type depends on the bare option:

  • { bare: true }BareRepo
  • Otherwise → WorktreeRepo
Parameters
path

string

opts

InitOpts & object & ExecOpts

Returns

Promise<BareRepo>

Call Signature

init(path, opts?): Promise<WorktreeRepo>

Defined in: src/core/git.ts:436

Parameters
path

string

opts?

InitOpts & ExecOpts

Returns

Promise<WorktreeRepo>


lsRemote()

lsRemote(url, opts?): Promise<LsRemoteResult>

Defined in: src/core/git.ts:443

List references in a remote repository

Wraps: git ls-remote <url>

Parameters

url

string

opts?

LsRemoteOpts & ExecOpts

Returns

Promise<LsRemoteResult>


open()

open(path, opts?): Promise<WorktreeRepo>

Defined in: src/core/git.ts:370

Open an existing worktree repository

This is the most common use case. Throws GitError if the repository is bare.

Parameters

path

string

Path to the repository working directory

opts?

GitOpenOptions

Environment isolation and credential options

Returns

Promise<WorktreeRepo>

WorktreeRepo

Throws

GitError with kind ‘NotWorktreeRepo’ if the repository is bare


openBare()

openBare(path, opts?): Promise<BareRepo>

Defined in: src/core/git.ts:382

Open an existing bare repository

Throws GitError if the repository is not bare.

Parameters

path

string

Path to the bare repository (git-dir)

opts?

GitOpenOptions

Environment isolation and credential options

Returns

Promise<BareRepo>

BareRepo

Throws

GitError with kind ‘NotBareRepo’ if the repository is not bare


openRaw()

openRaw(path, opts?): Promise<WorktreeRepo | BareRepo>

Defined in: src/core/git.ts:407

Open an existing repository without type guarantee

Returns either WorktreeRepo or BareRepo depending on the repository type. Use this when you don’t know the repository type at compile time. You can use isWorktree() or isBare() methods for runtime type checking.

Parameters

path

string

Path to the repository (workdir or git-dir)

opts?

GitOpenOptions

Environment isolation and credential options

Returns

Promise<WorktreeRepo | BareRepo>

WorktreeRepo or BareRepo depending on repository type

Example

const repo = await git.openRaw('/path/to/repo');
if (await repo.isWorktree()) {
// repo is WorktreeRepo at runtime
const status = await (repo as WorktreeRepo).status();
} else if (await repo.isBare()) {
// repo is BareRepo at runtime
await (repo as BareRepo).fetch({ remote: 'origin' });
}

raw()

raw(argv, opts?): Promise<RawResult>

Defined in: src/core/git.ts:457

Execute a raw git command (repository-agnostic)

Wraps: git <argv...>

Parameters

argv

string[]

opts?

ExecOpts

Returns

Promise<RawResult>


version()

version(opts?): Promise<string>

Defined in: src/core/git.ts:450

Get git version

Wraps: git --version

Parameters

opts?

ExecOpts

Returns

Promise<string>