Skip to content

Basic Usage

Overview

type-git provides two main interfaces:

  • Git: Repository-independent operations (clone, init, version)
  • Repo: Repository-dependent operations (status, commit, branch, etc.)

Working with Repositories

Cloning a Repository

import { TypeGit } from 'type-git/node';
const git = new TypeGit();
// Simple clone
await git.clone('https://github.com/user/repo.git', './repo');
// Clone with options
await git.clone('https://github.com/user/repo.git', './repo', {
depth: 1, // Shallow clone
branch: 'develop', // Specific branch
});

Opening an Existing Repository

const repo = await git.open('./repo');

Initializing a New Repository

await git.init('./new-repo');
const repo = await git.open('./new-repo');

Common Operations

Checking Status

const status = await repo.status();
for (const file of status.files) {
console.log(`${file.path}: ${file.workingTree} / ${file.index}`);
}

Staging and Committing

// Stage files
await repo.add(['file1.txt', 'file2.txt']);
// Commit
await repo.commit('feat: add new feature');

Branch Operations

// List branches
const branches = await repo.branch.list();
// Create branch
await repo.branch.create('feature/new-feature');
// Switch branch
await repo.switch('feature/new-feature');

Next Steps

See Practical Patterns for:

  • Git LFS operations
  • Progress tracking
  • Abort control
  • Error handling