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.
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:
pathandcontent. A string is sent as UTF-8, and bytes (Uint8Arrayorbytes) as base64.modeis100644for a regular file (the default),100755for an executable, or120000for a symlink whose content is its target. - Delete:
pathanddelete: true. The path must be a file in the parent commit. Directories can’t be deleted as a whole: delete each file in them.
docs and write docs/index.md in one commit.
Which parent the commit gets
- If
branchexists, its head.baseRefis ignored. - If
branchdoesn’t exist andbaseRefis set, the commitbaseRefnames. This creates the branch. - 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.
main:
Check the branch head
A commit and a push to the same branch never interleave: they run one after the other. WithoutexpectedHead, 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.