expectedHeadSha),
repo.createCommit().send() throws a RefUpdateError containing the status, reason, and ref
details.
Builder Methods
| Method | Description |
|---|---|
addFile(path, source, options) | Attach bytes, async iterables, readable streams, or buffers. |
addFileFromString(path, contents, options) | Add UTF-8 text files. |
deletePath(path) | Remove files or folders. |
send() | Finalize the commit and receive metadata about the new commit. |
Options
| Parameter | Type | Description |
|---|---|---|
targetBranch | Required | Branch name that will receive the commit (for example main). |
commitMessage | Required | The commit message. |
author | Required | Provide name and email for the commit author. |
expectedHeadSha | Optional | Commit SHA that must match the remote tip; omit to fast-forward unconditionally. |
baseBranch | Optional | Mirrors the base_branch metadata field. Point to an existing branch whose tip should seed targetBranch if it does not exist. When bootstrapping a new branch, omit expectedHeadSha so the service copies from baseBranch; if both fields are provided and the branch already exists, the expectedHeadSha guard still applies. |
ephemeral | Optional | Store the branch under the refs/namespaces/ephemeral/... namespace. When enabled, the commit is kept out of the primary Git remotes (for example, GitHub) but remains available through storage APIs. |
ephemeralBase | Optional | Use alongside baseBranch when the seed branch also lives in the ephemeral namespace. Requires baseBranch to be set. |
committer | Optional | Provide name and email. If omitted, the author identity is reused. |
signal | Optional | Abort an in-flight upload with AbortController. |
targetRef | Deprecated, Optional | Fully qualified ref (for example refs/heads/main). Prefer targetBranch. |
Files are chunked to 4 MiB segments under the hood, so you can stream large assets without buffering them entirely in memory. File paths are normalized relative to the repository root. ThetargetBranchmust already exist on the remote repository unless you providebaseBranch(or the repository has no refs). To initialize an empty repository, point to its default branch and omitexpectedHeadSha. To seed a missing branch inside an existing repo, setbaseBranchto the branch you want to copy and omitexpectedHeadShaso the service clones that tip before applying your changes.
Streaming Large Files
Use streams or async generators to upload large files without loading them into memory:Response
Thesend() method returns the following:
| Field | Type | Description |
|---|---|---|
commitSha (TypeScript)commit_sha (Python) | String | The SHA of the created commit |
treeSha (TypeScript)tree_sha (Python) | String | The SHA of the commit’s tree object |
targetBranch (TypeScript)target_branch (Python) | String | The branch that received the commit |
packBytes (TypeScript)pack_bytes (Python) | Number | Size of the uploaded pack in bytes |
blobCount (TypeScript)blob_count (Python) | Number | Number of blobs in the commit |
refUpdate (TypeScript)ref_update (Python) | Object | Contains branch, oldSha/old_sha, and newSha/new_sha |