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 cloneawait git.clone('https://github.com/user/repo.git', './repo');
// Clone with optionsawait 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 filesawait repo.add(['file1.txt', 'file2.txt']);
// Commitawait repo.commit('feat: add new feature');Branch Operations
// List branchesconst branches = await repo.branch.list();
// Create branchawait repo.branch.create('feature/new-feature');
// Switch branchawait repo.switch('feature/new-feature');Next Steps
See Practical Patterns for:
- Git LFS operations
- Progress tracking
- Abort control
- Error handling