Skip to content

Branches & commits

functionlistBranches
listBranches(repo: Repo): Promise<Branch[]>

Returns: Promise<Branch[]>

Every branch with its tip commit — { name, commit, isDefault }[]. [] for an empty repository, not an error.

createBranchFrom(repo: Repo, name: string, startPoint?: string): Promise<void>
ParameterTypeDescription
namestringThe new branch name.
startPoint?stringDefaults to "main".

Creates name pointing at the tip of startPoint. No checkout — this package targets bare repositories.

deleteBranchByName(repo: Repo, name: string): Promise<void>
ParameterTypeDescription
namestringThe branch to delete.

Validated internally — git.deleteBranch has no built-in ref-format check the way git.branch does, so this validates name before it ever reaches isomorphic-git.

assertBranchExists(repo: Repo, name: string): Promise<void>
ParameterTypeDescription
namestringThe branch to check.

Throws (isomorphic-git’s NotFoundError) unless the branch resolves. Useful as a cheap existence guard before a more expensive operation.

authorNow builds a CommitAuthor stamped with the current time — the shape every commit-writing function below expects:

interface CommitAuthor {
name: string;
email: string;
timestamp: number;
timezoneOffset: number;
}
const author = authorNow('Ada', 'ada@example.com');
commitFilesToBare(repo: Repo, options: { branch, message, author, files }): Promise<string>
ParameterTypeDescription
branchstringThe branch to commit onto (created if it doesn't exist).
messagestringCommit message.
authorCommitAuthorFrom authorNow or your own.
filesArray<{ path, content }>content is string | Uint8Array.

Returns: Promise<string>

Writes a commit directly to the bare repo — no worktree, no checkout. Each blob is content-addressed and independent of the others, so all files in the batch are written in parallel.

deleteFileFromBare(repo: Repo, options: { branch, filePath, message, author }): Promise<string>
ParameterTypeDescription
branchstringThe branch to commit onto.
filePathstringThe path to remove.
messagestringCommit message.
authorCommitAuthor

Returns: Promise<string>

Commits the removal of one file. Throws if the branch is empty (nothing to remove).

writeCommitToBare(repo: Repo, options: { branch, message, author, buildTree }): Promise<string>
ParameterTypeDescription
branchstringThe branch to commit onto.
messagestringCommit message.
authorCommitAuthor
buildTree(parentTreeOid?: string) => Promise<string>Receives the parent tree oid (undefined for an empty repo), returns the new root tree oid.

Returns: Promise<string>

The primitive commitFilesToBare/deleteFileFromBare are built on — reach for it directly when neither fits (a multi-step tree rewrite, a merge commit with a synthetic tree). Handles the parent-resolution, commit-object, and ref-update mechanics; you own tree construction via buildTree.

Serialize concurrent writers to the same repo externally (a per-repo lock) — the resolve-parent → write-commit → update-ref sequence is not atomic on object storage.