Git Client API¶
The Git plugin adds core Git operations to Titan through a high-level client and reusable workflows. It covers branches, commits, status inspection, diffs, remotes, stashes, tags, and worktrees.
This page documents the plugin from a functional point of view, while also showing how each capability is called and which parameters it needs.
Requirements¶
To use the Git plugin in a project:
- Enable the
gitplugin in.titan/config.toml - Install the
gitCLI and make sure it is available inPATH - Run Titan inside a Git repository
Example project configuration:
Accessing the client¶
In Titan code, the public entry point is the Git plugin client:
The client returns ClientResult[...] values. In practice, this means each call can succeed with data or return an error result.
Branch operations¶
Get the current branch¶
Returns the currently checked out branch name.
Call:
Parameters:
- No parameters.
List branches¶
Returns local branches, or remote branches when requested.
Call:
Parameters:
remote: Optional. Set toTrueto list remote branches instead of local ones.
List recently used branches¶
Returns local branches ordered by how recently they were worked on: the branches HEAD was switched to come first (read from the reflog), then the rest by the date of their last commit. Each branch carries that date both raw (last_commit_date) and ready to show (formatted_date, e.g. "3 d").
Call:
Parameters:
limit: Optional. Maximum number of branches to return.reflog_entries: Optional. How far back in the reflog to look for checkouts.
Create a branch¶
Creates a new branch from a starting point.
Call:
Parameters:
branch_name: Required. New branch name.start_point: Optional. Git ref to branch from.
Create a branch and switch to it¶
Creates a branch and checks it out in one git checkout -b, so there is no state
where the branch exists but is not checked out. Uncommitted work is carried over, as
git always carries it to a branch starting at HEAD.
Call:
Parameters:
branch_name: Required. New branch name.start_point: Optional. Git ref to branch from.
Delete a branch¶
Deletes a branch directly.
Call:
Parameters:
branch: Required. Branch name to delete.force: Optional. Force deletion.
Delete a branch safely¶
Deletes a branch only if it is not considered protected.
Call:
Parameters:
branch: Required. Branch name to delete.force: Optional. Force deletion.
Checkout a branch¶
Switches the repository to another branch.
Call:
Parameters:
branch: Required. Branch name to checkout.
Check whether a branch exists on remote¶
Checks if a branch already exists in a remote repository.
Call:
Parameters:
branch: Required. Branch name.remote: Optional. Remote name.
Update a branch from remote¶
Fetches and fast-forwards a branch from the remote.
Call:
Parameters:
branch: Required. Branch to update.remote: Optional. Remote name. Defaults to the configured default remote.
Update from the configured main branch¶
Updates the current branch from the configured main branch.
Call:
Parameters:
- No parameters.
Checkout safely¶
Stores the current branch, optionally stashes local changes, and then switches branches.
Call:
Parameters:
branch: Required. Branch to checkout.auto_stash: Optional. Automatically stash uncommitted changes first.
Return to the original branch¶
Returns to the branch previously saved by safe_checkout.
Call:
Parameters:
- No parameters.
Check whether a branch is protected¶
Checks if a branch name is treated as protected by the client.
Call:
Parameters:
branch: Required. Branch name.
Commit operations¶
Create a commit¶
Creates a commit from the current working tree.
Call:
Parameters:
message: Required. Commit message.all: Optional. Include tracked modified files automatically.no_verify: Optional. Skip Git hooks.
Create a commit for specific files¶
Creates a commit only for the files passed in the call.
Call:
client.commit_files(
files=["src/search.py", "tests/test_search.py"],
message="test: cover search filters",
no_verify=True,
)
Parameters:
files: Required. Files to include in the commit.message: Required. Commit message.no_verify: Optional. Skip Git hooks.
Get the current commit SHA¶
Returns the SHA of HEAD.
Call:
Parameters:
- No parameters.
Get the commit SHA for a ref¶
Resolves any Git ref to its commit SHA.
Call:
Parameters:
ref: Required. Any Git ref.
Get the merge base of two refs¶
Returns the SHA of the best common ancestor of two refs, the commit a pull request's diff is computed against.
Call:
Parameters:
ref_a: Required. A Git ref.ref_b: Required. A Git ref.
Get a file as it is at a ref¶
Returns the content of a file at any ref without checking anything out, or None when the
file does not exist at that ref (for example, a file a change adds). Content that is not text
is returned as a ClientError.
Call:
Parameters:
ref: Required. A commit SHA, branch or tag.path: Required. The repository-relative file path.
Get commits versus base¶
Returns commit messages from the base branch up to HEAD.
Call:
Parameters:
- No parameters.
Get commits in a branch compared to another branch¶
Returns the commits present in the head branch but not in the base branch.
Call:
Parameters:
base_branch: Required. Base branch.head_branch: Required. Head branch.
Get commits between refs¶
Returns commits reachable from one ref but not another.
Call:
Parameters:
base_ref: Required. Base ref.head_ref: Optional. Head ref.
Count commits ahead of a base branch¶
Counts how many commits the current branch is ahead of another branch.
Call:
Parameters:
base_branch: Optional. Base branch to compare against.
Count unpushed commits¶
Counts how many commits have not been pushed to the remote yet.
Call:
Parameters:
branch: Optional. Branch to inspect. Uses the current branch when omitted.remote: Optional. Remote name.
Status operations¶
Get repository status¶
Returns a structured view of the current repository state.
Call:
Parameters:
- No parameters.
Result: UIGitStatus with branch, is_clean, modified_files,
untracked_files, staged_files, ahead, behind, has_upstream (False when the
branch tracks nothing, so the counts are 0 for that reason), and the pre-formatted
clean_icon, status_summary and sync_status.
List untracked files¶
Returns every untracked file one by one, honouring .gitignore. Unlike
get_status().untracked_files, a new directory is expanded into its files and
ignored files (build output, __pycache__) are never listed.
Call:
Parameters:
- No parameters.
Check for uncommitted changes¶
Returns whether the repository has local changes not yet committed.
Call:
Parameters:
- No parameters.
Stage, unstage or discard one file¶
Three per-file actions on the index and the working tree. Each returns ClientResult[None]
(STAGE_ERROR, UNSTAGE_ERROR, DISCARD_ERROR on failure).
Call:
client.stage_file("src/app.py") # git add --all -- path: a change, a new file or a deletion
client.unstage_file("src/app.py") # git reset -- path: leaves the changes in the working tree
client.discard_file("src/app.py") # throws the unstaged changes away; irreversible
discard_file restores a tracked file to what the index holds (staged changes stay) and
deletes an untracked file. Callers should ask for confirmation first.
Parameters:
path(required): path relative to the repository root.
Diff operations¶
Get a diff between refs¶
Returns the diff between two refs.
Call:
Parameters:
base_ref: Required. Base ref.head_ref: Optional. Head ref.
Get the full uncommitted diff¶
Returns the diff of all local changes.
Call:
Parameters:
- No parameters.
Get the staged diff¶
Returns only the staged changes.
Call:
Parameters:
- No parameters.
Get the unstaged diff¶
Returns only the unstaged changes.
Call:
Parameters:
- No parameters.
Get the diff for one file¶
Returns the diff for a single file path.
Call:
Parameters:
file_path: Required. File path to inspect.
Get the diff between branches¶
Returns the diff between two branches, with configurable context lines.
Call:
client.get_branch_diff(
base_branch="main",
head_branch="feature/search",
context_lines=3,
use_remote=False,
)
Parameters:
base_branch: Required. Base branch.head_branch: Required. Head branch.context_lines: Optional. Number of diff context lines.use_remote: Optional. Treat both branches as remote refs.
Get per-file change counters between branches¶
Returns a UIFileChurn list with exact additions/deletions per changed file
(git diff --numstat). Binary files are included with is_binary=True and zero
counters. Useful when an API source reports zeroed counters for files whose diff
it cannot render.
Call:
Parameters:
base_branch: Required. Base branch.head_branch: Required. Head branch.use_remote: Optional. Treat both branches as remote refs.
Get per-file counters of uncommitted changes¶
Returns one UIFileChurn per tracked file that differs from HEAD (working tree
and index together), with additions, deletions and is_binary. It is
read-only and safe to call repeatedly, e.g. from a timer. Prefer it over
get_uncommitted_diff_stat(), which marks untracked files with intent-to-add as
a side effect.
Call:
Parameters:
include_untracked: Optional (defaultFalse). Also count new, untracked files (honouring.gitignore): each one's lines as additions; binary or unreadable files asis_binary=Truewith zero counters.
List the files a commit changed¶
Returns one UIFileChange per file (path, status as A/M/D, additions,
deletions, is_binary). A merge commit is compared with its first parent. Renames
come as a delete plus an add. Returns a ClientError (DIFF_ERROR) for an unknown ref.
Call:
Parameters:
sha: Required. Commit hash or any ref that names one.
Get one file's diff in a commit¶
Returns a UIFileDiff: the file's hunks, each with its @@ header and UIDiffLines
(kind is add, del, context or no_newline; old_no/new_no are the line numbers on
the side the line exists on), plus additions, deletions and is_binary. A binary file has
no hunks. Callers draw it directly; they do not parse diff text.
Call:
Parameters:
sha: Required. Commit hash or any ref that names one.path: Required. File path asget_commit_filesreports it.context_lines: Optional (default3). Unchanged lines around each change.
List the uncommitted files, staged and unstaged apart¶
Returns a UIUncommittedFiles with staged (index against HEAD) and unstaged (working
tree against the index), each a list of UIFileChange. Untracked files (honouring
.gitignore) are listed with the unstaged ones with status ? and their lines as
additions. Read-only and safe to call from a timer: it never marks files with intent-to-add.
Call:
Get one uncommitted file's diff¶
Returns a UIFileDiff (see above) for the staged or the unstaged side of a file. An
untracked file is shown as all additions, without touching the index. Unlike
get_file_diff, which compares the working tree with HEAD as raw text, this keeps the two
sides apart and returns parsed hunks.
Call:
Parameters:
path: Required. File path asget_uncommitted_filesreports it.staged: Optional (defaultFalse). Read the index side instead of the working tree's.context_lines: Optional (default3). Unchanged lines around each change.
List files changed between two refs¶
Returns the paths that differ between two refs (commits, branches or tags), one entry per path. Renames report both the old and the new path.
Call:
Parameters:
base_ref: Required. Base ref, used verbatim (no remote prefixing).head_ref: Required. Head ref, used verbatim.
Get a diff stat between refs¶
Returns a summary of file-level changes between refs.
Call:
Parameters:
base_ref: Required. Base ref.head_ref: Optional. Head ref.
Get the diff stat for uncommitted changes¶
Returns a compact summary of local changes.
Call:
Parameters:
- No parameters.
Get the diff stat between branches¶
Returns a compact summary of changes between two branches.
Call:
Parameters:
base_branch: Required. Base branch.head_branch: Required. Head branch.
Merge operations¶
Merge a ref into the current branch¶
Merges a ref into the checked out branch without opening an editor. A conflicted merge is not an error: the call returns ClientSuccess with a UIMergeResult whose status is MergeStatus.CONFLICTED and whose conflicted_files lists the unmerged paths, so the caller can drive conflict resolution.
Call:
Parameters:
ref: Required. Ref to merge, usually a remote-tracking ref such asorigin/develop.target_branch: Optional. Branch receiving the merge. Used for display only.no_ff: Optional. Force a merge commit even when a fast-forward is possible.
Returns: ClientResult[UIMergeResult] with status in up_to_date, fast_forward, merged, conflicted.
List conflicted files¶
Returns the paths git reports as unmerged in the index. Empty when the tree is clean.
Note that git keeps a path unmerged until it is staged, so a file whose conflict was already fixed in the editor still shows up here. Use List unresolved conflicts when you need to know whether the conflicts are actually gone.
Call:
Parameters: none.
List unresolved conflicts¶
Returns only the unmerged paths whose working-tree content still contains conflict markers (<<<<<<< … >>>>>>>). Files that were resolved but not staged are excluded; paths that cannot be read (deleted or binary) are kept in the list so the caller can decide.
Call:
Parameters: none.
List the conflicts between two refs¶
Returns the files that would conflict if base_ref were merged into head_ref, without touching the working tree, the index or HEAD: git merge-tree merges in memory, so this can be asked about a branch that is not checked out. An empty list means the merge would be clean. Requires git 2.38 or newer; an unknown ref (or an older git) comes back as a MERGE_TREE_FAILED error.
Remote-tracking refs are used as they are, so fetch first if the answer must be current.
Call:
Parameters:
base_ref: Required. Ref that would be merged in.head_ref: Required. Ref receiving the merge.
Check whether a merge is in progress¶
Returns True while MERGE_HEAD exists, that is, while a merge is stopped and waiting to be completed or aborted.
Call:
Parameters: none.
Stage every change¶
Stages the whole working tree, including untracked files. Used to mark conflicts as resolved before completing a merge.
Call:
Parameters: none.
Complete an in-progress merge¶
Commits the staged merge using the message git prepared, without opening an editor.
Call:
Parameters:
| Parameter | Required | Default | Description |
|---|---|---|---|
no_verify |
No | True |
Skip pre-commit and commit-msg hooks. Skipping is the default because the commit only carries git's own merge message, and a hook that fails here leaves the merge stopped with everything staged. |
Returns: ClientResult[str] with the merge commit SHA.
Abort an in-progress merge¶
Restores the state from before the merge started.
Call:
Parameters: none.
Remote operations¶
Push to a remote¶
Pushes commits to a remote branch.
Call:
Parameters:
remote: Optional. Remote name.branch: Optional. Branch to push. Uses the current branch when omitted.set_upstream: Optional. Set the upstream tracking branch.tags: Optional. Push tags too.
Push a tag¶
Pushes a single tag to a remote.
Call:
Parameters:
tag_name: Required. Tag name.remote: Optional. Remote name.
Pull from a remote¶
Pulls changes from a remote branch.
Call:
Parameters:
remote: Optional. Remote name.branch: Optional. Branch to pull.
Fetch from a remote¶
Fetches changes without merging them.
Call:
Parameters:
remote: Optional. Remote name.branch: Optional. Branch to fetch.all: Optional. Fetch all remotes.
Extract GitHub repository info¶
Parses the remote URL and returns the GitHub owner and repository name when available.
Call:
Parameters:
- No parameters.
Stash operations¶
Create a stash¶
Stashes current local changes.
Call:
Parameters:
message: Optional. Stash message.include_untracked: Optional. Also stash new, untracked files (not ignored ones), so the tree ends up clean.
Apply a stash¶
Applies a stash and keeps it in the list.
Call:
Parameters:
stash_ref: Optional. Stash reference (stash@{1}) or stash commit hash. Defaults to the latest.
Returns: ClientResult[bool]. Error code: STASH_APPLY_ERROR (a conflict, say).
Drop a stash¶
Drops one stash. It cannot be undone.
Call:
Parameters:
stash_ref: Required. Stash reference, aslist_stashesreports it.
Returns: ClientResult[bool]. Error code: STASH_DROP_ERROR.
Clear the stash list¶
Drops every stash. It cannot be undone.
Call:
Parameters:
- No parameters.
Returns: ClientResult[bool], True once the list is empty. Error code: STASH_CLEAR_ERROR.
List the stashes¶
Lists the stashes, newest first.
Call:
Parameters:
- No parameters.
Returns: ClientResult[List[UIGitStash]], each with ref (stash@{0}), hash (its commit, stable while the list shifts), branch it was made on, message and formatted_date ("2 hours ago"). A stash's hash is a merge commit, so get_commit_files(hash) and get_commit_file_diff(hash, path) give its changes to tracked files; files stashed as untracked are not in them. An empty list when there are none. Error code: STASH_LIST_ERROR.
Pop a stash¶
Applies and removes a stash.
Call:
Parameters:
stash_ref: Optional. Specific stash reference.
Find a stash by message¶
Looks up a stash using its message.
Call:
Parameters:
message: Required. Stash message to search for.
Restore a stash by message¶
Finds a stash by message and restores it.
Call:
Parameters:
message: Required. Stash message to restore.
Tag operations¶
Create a tag¶
Creates an annotated tag.
Call:
Parameters:
tag_name: Required. Tag name.message: Required. Tag annotation message.ref: Optional. Ref to tag.
Delete a tag¶
Deletes a local tag.
Call:
Parameters:
tag_name: Required. Tag name.
Check whether a tag exists locally¶
Checks if a tag is present in the local repository.
Call:
Parameters:
tag_name: Required. Tag name.
Check whether a tag exists on remote¶
Checks if a tag exists in a remote repository.
Call:
Parameters:
tag_name: Required. Tag name.remote: Optional. Remote name.
List tags¶
Returns the tags available in the repository.
Call:
Parameters:
- No parameters.
Worktree operations¶
Create a worktree¶
Creates a new Git worktree.
Call:
client.create_worktree(
path="../repo-search-worktree",
branch="feature/search",
create_branch=False,
detached=False,
)
Parameters:
path: Required. Filesystem path for the worktree.branch: Required. Branch to attach to the worktree.create_branch: Optional. Create the branch if needed.detached: Optional. Create the worktree in detached mode.
Remove a worktree¶
Removes an existing worktree.
Call:
Parameters:
path: Required. Worktree path.force: Optional. Force removal.
Prune stale worktree metadata¶
Clears Git's records for worktrees whose directories no longer exist.
Git keeps administrative data under .git/worktrees for every registered worktree. If
the directory is deleted by hand, or a removal is interrupted, that record survives and
blocks the path: create_worktree reports it as already registered, while
remove_worktree reports it as "not a working tree". Pruning is the only way to clear
it, so call this before recreating a worktree at a path a previous run may have used.
Call:
Parameters:
- No parameters.
List worktrees¶
Returns all worktrees for the repository.
Call:
Parameters:
- No parameters.
Run a Git command in a worktree¶
Runs a Git command inside a specific worktree.
Call:
Parameters:
worktree_path: Required. Worktree path.args: Required. Git arguments to execute.
Get recent commits from a worktree¶
Returns recent commits from a specific worktree, in topological order (parents after their children).
Call:
client.get_commits(worktree_path="../repo-search-worktree", limit=10)
client.get_commits(worktree_path=".", limit=50, all_branches=True)
Parameters:
worktree_path: Required. Worktree path.limit: Optional. Maximum number of commits.all_branches: Optional. Walk every ref instead of HEAD only, asgit log --alldoes.
Each UIGitCommit carries pr_number: the PR a squash merge landed, from the
(#1234) GitHub appends to its subject (None otherwise).
models.formatting.split_squash_pr_suffix(subject) returns the subject
without it and the number.
It also carries parents (full hashes; more than one means a merge) and refs
(the branches and tags pointing at it, as plain names), tags (those of refs that are tags) and remote_refs (those that are remote branches, origin/main; a remote's own HEAD is left out).
operations.build_commit_graph(commits) turns that list into UIGitGraphRows —
the lane glyphs of a git log --graph drawing, one row per commit plus a link
row wherever edges fork out — and operations.graph_lanes(rows) says how many
columns they need.
Get the worktree diff stat¶
Returns a diff summary for local changes in a worktree.
Call:
Parameters:
worktree_path: Required. Worktree path.
Checkout a branch in a worktree¶
Checks out, or creates, a branch inside a specific worktree.
Call:
client.checkout_branch_in_worktree(
worktree_path="../repo-search-worktree",
branch_name="feature/search",
force=False,
)
Parameters:
worktree_path: Required. Worktree path.branch_name: Required. Branch name.force: Optional. Force the checkout.
Commit changes in a worktree¶
Stages and commits changes inside a worktree.
Call:
client.commit_in_worktree(
worktree_path="../repo-search-worktree",
message="feat: add search filters",
add_all=True,
no_verify=False,
)
Parameters:
worktree_path: Required. Worktree path.message: Required. Commit message.add_all: Optional. Stage all tracked changes before committing.no_verify: Optional. Skip Git hooks.
Push from a worktree¶
Pushes a branch from a specific worktree to a remote.
Call:
client.push_from_worktree(
worktree_path="../repo-search-worktree",
branch="feature/search",
remote="origin",
)
Parameters:
worktree_path: Required. Worktree path.branch: Required. Branch to push.remote: Optional. Remote name.
Related workflows¶
The Git plugin ships with workflows that use these capabilities directly:
commit-ai: Checks repository status, shows a summary of local changes, generates a commit message with AI, creates the commit, and pushes it
These workflows can be used as-is or extended from .titan/workflows/.