Branches and Git Operations
The Git API (Level 2) provides programmatic access to branches, commit history, and diffs without needing a local git binary.
Status:
log()anddiff()are fully functional.createBranch(),listBranches(),deleteBranch(), andmerge()require server-side RPCs that haven’t shipped yet — calling them will throw an error.
Quickstart
Section titled “Quickstart”import { Client } from "@githosted/sdk";
const client = new Client();const repo = client.repo("my-project");
// View commit historyconst commits = await repo.log({ limit: 10 });
// Get a diff between two branchesconst diff = await repo.diff("main", "feature/new-api");API Reference
Section titled “API Reference”repo.log(options?)
Section titled “repo.log(options?)”Get the commit log.
// Recent commitsconst commits = await repo.log({ limit: 20 });for (const c of commits) { console.log(`${c.hash.slice(0, 7)} ${c.subject} (${c.authorName})`);}
// Commits on a specific branchconst commits = await repo.log({ ref: "develop", limit: 10 });
// Commits touching a specific fileconst history = await repo.log({ path: "src/main.ts", limit: 5 });Each commit has: hash, authorName, authorEmail, committedAt (Date), subject.
repo.diff(baseRef, headRef)
Section titled “repo.diff(baseRef, headRef)”Get the diff between two refs.
const diff = await repo.diff("main", "feature/new-api");console.log(diff.patch); // unified diff outputrepo.createBranch(name, options?)
Section titled “repo.createBranch(name, options?)”Create a new branch.
const branch = await repo.createBranch("feature/new-api", { from: "main" });repo.listBranches()
Section titled “repo.listBranches()”List all branches.
const branches = await repo.listBranches();for (const b of branches) { console.log(`${b.name} ${b.isDefault ? "(default)" : ""}`);}repo.merge(source, options)
Section titled “repo.merge(source, options)”Merge a branch.
const result = await repo.merge("feature/new-api", { into: "main", message: "Merge feature/new-api",});