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.create_branch(),list_branches(), andmerge()require server-side RPCs that haven’t shipped yet — calling them will raiseNotImplementedError.
Quickstart
Section titled “Quickstart”from githosted import Client
client = Client()repo = client.repo("my-project")
# View commit historycommits = repo.log(limit=10)
# Get a diff between two branchesdiff = repo.diff("main", "feature/new-api")API Reference
Section titled “API Reference”repo.log(path, *, ref, limit)
Section titled “repo.log(path, *, ref, limit)”Get the commit log.
# Recent commitscommits = repo.log(limit=20)for c in commits: print(f"{c.hash[:7]} {c.subject} ({c.author_name})")
# Commits on a specific branchcommits = repo.log(ref="develop", limit=10)
# Commits touching a specific filehistory = repo.log("src/main.py", limit=5)Each commit has: hash, author_name, author_email, committed_at (datetime), subject.
repo.diff(base_ref, head_ref)
Section titled “repo.diff(base_ref, head_ref)”Get the diff between two refs.
diff = repo.diff("main", "feature/new-api")print(diff.patch) # unified diff outputrepo.create_branch(name, *, from_ref)
Section titled “repo.create_branch(name, *, from_ref)”Create a new branch.
repo.create_branch("feature/new-api", from_ref="main")repo.list_branches()
Section titled “repo.list_branches()”List all branches.
branches = repo.list_branches()repo.merge(source, *, into, message)
Section titled “repo.merge(source, *, into, message)”Merge a branch.
repo.merge("feature/new-api", into="main", message="Merge feature/new-api")