Skip to content

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() and diff() are fully functional. create_branch(), list_branches(), and merge() require server-side RPCs that haven’t shipped yet — calling them will raise NotImplementedError.

from githosted import Client
client = Client()
repo = client.repo("my-project")
# View commit history
commits = repo.log(limit=10)
# Get a diff between two branches
diff = repo.diff("main", "feature/new-api")

Get the commit log.

# Recent commits
commits = repo.log(limit=20)
for c in commits:
print(f"{c.hash[:7]} {c.subject} ({c.author_name})")
# Commits on a specific branch
commits = repo.log(ref="develop", limit=10)
# Commits touching a specific file
history = repo.log("src/main.py", limit=5)

Each commit has: hash, author_name, author_email, committed_at (datetime), subject.

Get the diff between two refs.

diff = repo.diff("main", "feature/new-api")
print(diff.patch) # unified diff output

Create a new branch.

repo.create_branch("feature/new-api", from_ref="main")

List all branches.

branches = repo.list_branches()

Merge a branch.

repo.merge("feature/new-api", into="main", message="Merge feature/new-api")