@ouranos/git
v0.1.2
Published
Typed Git operations wrapper using execa
Downloads
540
Readme
@ouranos/git
Typed Git operations wrapper using execa. Supports init, status, add, commit, push, fetch, diff, merge, rebase, and divergence detection.
Install
npm install @ouranos/gitUsage
import { Git } from '@ouranos/git';
// Initialize a git repository
await Git.init('/path/to/repo');
// Check status
const status = await Git.status('/path/to/repo');
// Stage and commit files
await Git.add('/path/to/repo', ['file1.ts', 'file2.ts']);
const hash = await Git.commit('/path/to/repo', 'Your commit message');
// Push to remote
await Git.push('/path/to/repo');
// Compare against remote
const { ahead, behind } = await Git.getDivergence('/path/to/repo', 'main');API
| Method | Description |
| ----------------------------------------------- | ---------------------------------------- |
| init(cwd) | Initialize a git repository |
| status(cwd) | Get git status (porcelain output) |
| add(cwd, files) | Stage files for commit |
| commit(cwd, message) | Create a commit, returns the commit hash |
| push(cwd, remote?, branch?) | Push to remote |
| getCurrentBranch(cwd) | Get current branch name |
| getCommitHash(cwd, ref?) | Get commit hash for a ref |
| diff(cwd, files) | Show staged diff for files |
| showChangedFiles(cwd, hash) | List files changed in a commit |
| showFileContent(cwd, file) | Get file content at HEAD |
| getRemoteUrl(cwd, remote?) | Get remote URL |
| fetch(cwd, remote?) | Fetch from remote |
| getDefaultBranch(cwd) | Get default branch name |
| getDivergence(cwd, branch, remote?) | Get ahead/behind counts |
| hasRemoteTrackingBranch(cwd, branch, remote?) | Check if remote tracking branch exists |
| mergeRemote(cwd, branch, remote?) | Merge remote into current branch |
| rebaseOntoRemote(cwd, branch, remote?) | Rebase onto remote tracking branch |
License
See LICENSE
