Branches & commits
Branches
Section titled “Branches”listBrancheslistBranches(repo: Repo): Promise<Branch[]>Returns: Promise<Branch[]>
Every branch with its tip commit — { name, commit, isDefault }[]. []
for an empty repository, not an error.
createBranchFromcreateBranchFrom(repo: Repo, name: string, startPoint?: string): Promise<void>| Parameter | Type | Description |
|---|---|---|
name | string | The new branch name. |
startPoint? | string | Defaults to "main". |
Creates name pointing at the tip of startPoint. No checkout — this
package targets bare repositories.
deleteBranchByNamedeleteBranchByName(repo: Repo, name: string): Promise<void>| Parameter | Type | Description |
|---|---|---|
name | string | The 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.
assertBranchExistsassertBranchExists(repo: Repo, name: string): Promise<void>| Parameter | Type | Description |
|---|---|---|
name | string | The branch to check. |
Throws (isomorphic-git’s NotFoundError) unless the branch resolves.
Useful as a cheap existence guard before a more expensive operation.
Commits
Section titled “Commits”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');commitFilesToBarecommitFilesToBare(repo: Repo, options: { branch, message, author, files }): Promise<string>| Parameter | Type | Description |
|---|---|---|
branch | string | The branch to commit onto (created if it doesn't exist). |
message | string | Commit message. |
author | CommitAuthor | From authorNow or your own. |
files | Array<{ 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.
deleteFileFromBaredeleteFileFromBare(repo: Repo, options: { branch, filePath, message, author }): Promise<string>| Parameter | Type | Description |
|---|---|---|
branch | string | The branch to commit onto. |
filePath | string | The path to remove. |
message | string | Commit message. |
author | CommitAuthor |
Returns: Promise<string>
Commits the removal of one file. Throws if the branch is empty (nothing to remove).
writeCommitToBarewriteCommitToBare(repo: Repo, options: { branch, message, author, buildTree }): Promise<string>| Parameter | Type | Description |
|---|---|---|
branch | string | The branch to commit onto. |
message | string | Commit message. |
author | CommitAuthor | |
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.