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.
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.
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 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.
Check for uncommitted changes¶
Returns whether the repository has local changes not yet committed.
Call:
Parameters:
- No parameters.
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.
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.
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.
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.
Call:
Parameters:
worktree_path: Required. Worktree path.limit: Optional. Maximum number of commits.
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/.