Skip to main content
repo.commit() makes one commit from a list of file changes and moves a branch to it. There’s no clone, no working tree, and no git binary, so it works from a serverless function, an edge runtime, or an agent tool that only needs to write a few files. The commit is a normal git commit: anyone who fetches the branch sees it, and it sends a push webhook like a push does.
The same call is archil.git.repos.commit(repoId, params) when you have only the ID.

Parameters

Each entry in files either writes a file or deletes one:
  • Write: path and content. A string is sent as UTF-8, and bytes (Uint8Array or bytes) as base64. mode is 100644 for a regular file (the default), 100755 for an executable, or 120000 for a symlink whose content is its target.
  • Delete: path and delete: true. The path must be a file in the parent commit. Directories can’t be deleted as a whole: delete each file in them.
Paths are relative and slash-separated, and each path can appear once per call. Deletes apply before writes, so you can delete the file docs and write docs/index.md in one commit.

Which parent the commit gets

  1. If branch exists, its head. baseRef is ignored.
  2. If branch doesn’t exist and baseRef is set, the commit baseRef names. This creates the branch.
  3. Otherwise, no parent: a root commit. That’s allowed only in an empty repo, so the first commit to a new repo needs no baseRef.
To start a feature branch from main:

Check the branch head

A commit and a push to the same branch never interleave: they run one after the other. Without expectedHead, a commit applies its changes on top of whatever the branch’s head is when it runs, which may include someone else’s push. Pass expectedHead to commit only if the branch hasn’t moved since you read it. If it has, the call fails with code head_mismatch, and currentHead holds the branch’s head, or null if the branch doesn’t exist. Pass 40 zeros to require that the branch doesn’t exist yet.
repo.commit() returns the new commit’s SHA, so a loop that makes several commits in a row can pass the previous result’s commit as the next call’s expectedHead.

Errors

Every error is an ArchilGitError. See Errors.

Limits

For larger changes, clone and push with git. See the quickstart.