CLI reference ¶
git sheet <command> — the command-line interface. Installs as both
gitsheets and git-sheet.
The CLI is a thin wrapper around the JS API. Every command resolves to an
operation on a Repository (or Sheet/Transaction).
Global flags ¶
| Flag | Default | Env |
|---|---|---|
--git-dir <path> |
discovered from cwd | GIT_DIR |
--root <path> |
/ |
GITSHEETS_ROOT |
--prefix <path> |
none | GITSHEETS_PREFIX |
--branch <name> / --no-branch |
gitsheets.branch git config, else HEAD’s branch |
GITSHEETS_BRANCH |
--submodule <path> / --no-submodule |
gitsheets.submodule git config, else none |
GITSHEETS_SUBMODULE |
--stage-pointer / --no-stage-pointer |
gitsheets.stagePointer git config, else off |
GITSHEETS_STAGE_POINTER |
--at <superproject-ref> |
none | GITSHEETS_AT |
--ref <ref> |
the default branch (the pinned commit under --at) |
GITSHEETS_REF |
--commit-to <ref> |
derived from --ref |
— |
--message <msg> |
auto-generated | — |
--author-name <name>, --author-email <email> |
git config | — |
--trailer <Key>=<value> (repeatable) |
none | — |
--prefix scopes records to a sub-tree under each sheet’s configured root —
useful for multi-tenant deployments where one git repo holds many tenants
under <root>/<tenant>/.... With --prefix tenant-a, a sheet whose config
declares root = 'users' reads/writes records at users/tenant-a/<path>.toml.
The sheet’s .gitsheets/<name>.toml config file is unaffected — only the
record data tree is scoped.
--branch selects the repository’s default branch — the branch commands
read from and commit to. It resolves flag → GITSHEETS_BRANCH →
gitsheets.branch git config → the branch HEAD points at, the same order
the library’s openRepo uses, so one git config gitsheets.branch data per
clone binds both the CLI and the application. --ref defaults to that
branch. Records on a branch that is never checked out need no working tree
and leave git status clean — see Headless data.
git config gitsheets.branch data # once per clone
gitsheets query users # reads the data branch
GITSHEETS_BRANCH=data gitsheets upsert users '{"slug":"jane"}'
gitsheets --branch data read users jane
--submodule <path> selects submodule mode: commands read and write the
data submodule at that path, whose HEAD is the superproject’s pointer to a
data snapshot. A write advances it, so git status in the superproject
reports modified: data (new commits) and nothing else; commit the pointer
with your code. It resolves flag → GITSHEETS_SUBMODULE →
gitsheets.submodule git config, and combines with --branch (a branch of
the submodule). Set the submodule up with
submodule init.
git config gitsheets.submodule data # once per clone
gitsheets upsert users '{"slug":"jane"}'
git add data && git commit -m "Add jane"
To skip an inherited binding for one run, --no-submodule reads and writes
the superproject itself and --no-branch uses the branch HEAD points at;
neither consults the environment variable or git config. An empty
GITSHEETS_SUBMODULE= or GITSHEETS_BRANCH= counts as unset and falls
through to git config, so use the flag to opt out.
GITSHEETS_SUBMODULE=data gitsheets --no-submodule query users # the superproject's own users sheet
Two more flags apply in submodule mode:
--stage-pointeralso stages the moved gitlink in the superproject’s index after each write, sogit commit -acarries it. It resolves flag →GITSHEETS_STAGE_POINTER→ the superproject’sgitsheets.stagePointer→ off, and takes git booleans (true/false,yes/no,on/off,1/0);--no-stage-pointerturns it off for one run. The library’sopenReporeads the same environment variable and config.--at <superproject-ref>(orGITSHEETS_AT) reads the data snapshot that superproject commit pins — the data a given code revision shipped with. Writes are refused (TransactionError, exit69). It is a one-run pin, like--ref, so it has no git config setting.
gitsheets --submodule data --at v1.2.0 query users # data as of the v1.2.0 release
git config gitsheets.stagePointer true # stage the pointer after every write
--ref <ref> pins what a command reads and the commit it builds on:
query, read, and aggregate read <ref>; normalize,
upsert --delete-missing, edit, infer, and rollup read <ref> and
commit onto it. Without --ref, both are the default branch.
Commands ¶
gitsheets upsert <sheet> [input] ¶
Insert or update one or more records.
gitsheets upsert users users.json
gitsheets upsert users - < records.jsonl
gitsheets upsert users '{"slug":"jane","email":"jane@x.org"}'
gitsheets upsert users users.csv --format=csv
gitsheets upsert users users.toml --format=toml
input is inline JSON (single record {...} or array [{...}, ...]),
a file path, or - for stdin.
Flags:
--format <json|toml|csv>— input format. Default: inferred from extension (*.toml→ TOML,*.csv→ CSV), otherwise JSON.--encoding <enc>— encoding for file/stdin input. Defaultutf8. Accepts any NodeBufferEncoding.--delete-missing— DESTRUCTIVE: full-replace mode. After upserting every input record, deletes any record in the sheet whose path isn’t in the input set, in the same transaction. If validation fails on any input record, the whole transaction rolls back and the tree is unchanged.--attachment <name>=<source>(repeatable) — attach a file alongside the (single) upserted record in the same transaction.<source>is a file path (relative to the input file’s directory, or cwd when input is stdin) or-for stdin (only one-per command). Requires a single-record input set.
gitsheets upsert users '{"slug":"jane"}' \
--attachment avatar.jpg=./assets/jane.jpg \
--attachment bio.md=-
--patch— treat each input record as an RFC 7396 JSON Merge Patch. Fields present in the sheet’s path template are split out as the query (which existing record to find); the remaining fields are merged into that record.nulldeletes a field. Cannot be combined with--delete-missingor--attachment.
# Update jane's email; delete her bio; add a team field.
gitsheets upsert users '{"slug":"jane","email":"new@x.org","bio":null,"team":"eng"}' --patch
For sheets whose template uses expressions (e.g., ${{ slug.toLowerCase() }}), the CLI does a best-effort identifier scan to find the query fields. If that doesn’t yield the right split, use the library API Sheet.patch(query, partial) directly.
TOML input supports three layouts: a [[records]] array of tables (recommended for multi-record files), a top-level table where every value is itself a table (each value becomes one record), or a single-record document.
CSV input uses the first row as a header. Cell values stay as strings — type coercion belongs in the consumer schema, not in CSV parsing.
Output (per record):
<blob-hash> <rendered-path>
gitsheets query <sheet> ¶
Read records. Output is newline-delimited JSON by default.
gitsheets query users
gitsheets query users --filter email=jane@x.org
gitsheets query users --filter status=active --filter project_id=p1
gitsheets query users --fields slug email --limit 100
gitsheets query users --format=csv --fields slug email
gitsheets query users --format=toml > users.toml
Flags:
--filter <field>=<value>(repeatable) — equality filter.field>=value,field<=value,field>value,field<valuebuild a range entry on the field (several bounds on one field merge into one range). Values are strings; an ISO 8601 value compares chronologically against datetime fields, and a range on a date-bucket path field prunes the tree walk — e.g.--filter 'publishedAt>=2026-01-01' --filter 'publishedAt<2026-04-01'.--fields <name>...— output column subset (order preserved)--limit <n>--format <json|csv|tsv|toml>— output format. Defaultjson(newline-delimited).--headers/--no-headers— emit a header row for CSV/TSV. Defaulttrue.--body/--no-body— for content-typed (markdown/mdx) sheets, include or suppress the body field in the output. Defaulttrue. Use--no-bodyfor bulk metadata pipelines on large bodies. No effect on TOML sheets.
TOML output emits a [[records]] array of tables, round-trippable through upsert --format=toml.
gitsheets aggregate <sheet> ¶
Compute ad-hoc aggregates over the records matching --filter. Output is one object with a key per --agg name.
gitsheets aggregate transactions --agg count=count --agg total=sum:amountCents
# {"count":1402,"total":98231100}
gitsheets aggregate transactions --filter 'postedAt>=2026-01-01' --agg total=sum:amountCents --group-by status
# {"total":{"pending":-500,"posted":3500}}
gitsheets aggregate repos --agg teams=distinct:targetTeam --format toml
Flags:
--agg <name>=<form>[:<field>](repeatable, at least one) —count, orsum/min/max/avg/distinctwith a field.--filter— as onquery.--group-by <field>— appliesgroupByto every aggregate; each result becomes an object keyed by the field’s string form. Records whose field isn’t a string, integer, or boolean don’t contribute.--format <json|toml>— defaultjson.
The fold runs in the core over the matching records, read without bodies, in canonical path order. An aggregate with nothing to fold is left out of the output, except count and sum (0). reduce snippets are library-only (sheet.aggregate). A field holding mixed kinds under min/max/distinct fails with AggregationError (exit 23). A malformed --agg clause is an argument error (exit 2).
gitsheets rollup <sheet> ¶
Materialize a rollup sheet: recompute every stale or missing rollup record and delete orphaned ones, in one commit — none when everything is fresh. Honors the transaction flags (--message, --author-*, --trailer, --ref, --commit-to, --prefix). Prints one <status> <partition> line per partition touched.
gitsheets rollup transactions-monthly
# recomputed 2026/03
# deleted 2025/11
gitsheets rollup transactions-monthly --check
# stale 2026/03
# (exit 1 — nothing written)
--check writes nothing, prints one stale / missing / orphaned line per partition that is not fresh, and exits 1 if there are any — the CI gate for a data branch other tools write to. Writing to a rollup sheet (upsert, edit, …) fails with TransactionError (sheet_derived, exit 69).
gitsheets read <sheet> <path> ¶
Read a single record by its rendered path.
gitsheets read users jane
gitsheets read users jane --format=toml
Flags:
--format <json|toml|csv|tsv>— output format. Default: pretty-printed JSON.
gitsheets edit <sheet> <path> ¶
Open a record in $EDITOR for interactive editing. On save:
- The CLI re-reads the tmpfile, parses it as TOML.
- If the file is byte-identical to what was written out, no commit is made (idempotent — no empty commits).
- Otherwise the parsed record is upserted in a transaction; validation, normalization, and path rendering all run.
Editor resolution: $VISUAL → $EDITOR → vi. The editor is spawned through a shell, so EDITOR="code --wait" and similar wrapped commands work. Exit-code 0 from the editor means “save”; anything else aborts without commit.
gitsheets edit users jane
Validation failures abort with a clear message rather than re-opening the editor — re-edit the input via gitsheets read users <path> --format=toml plus upsert if you need a second pass.
gitsheets check <sheet> <file> ¶
Verify a record file in the working tree is parseable, schema-valid, and in canonical form. Designed for two distinct workflows:
CI / pre-commit verification — exit non-zero if the file isn’t canonical; don’t touch it:
gitsheets check posts posts/hello.md
Post-edit auto-formatter — rewrite to canonical form; exit 0:
gitsheets check posts posts/hello.md --fix
Useful as a post-edit hook for AI agents that modify record files directly: the hook runs gitsheets check <sheet> $file --fix after each edit, leaving the file in canonical form (deep-sorted keys, normalized markdown body for content-typed sheets) and rejecting it loudly if it fails schema.
Exit codes:
0— file is canonical and valid (or--fixrewrote it)1— file is parseable + valid but not canonical (without--fix)22—ValidationError(schema)64—ConfigError(parse failed)
gitsheets normalize <sheet> ¶
Re-write every record in the sheet through canonical normalization in one
transaction. Use case: after upgrading [gitsheet.fields.<name>.sort] rules,
or after a manual edit that didn’t preserve canonical key order.
gitsheets normalize users
gitsheets init <sheet> ¶
Commit a starter .gitsheets/<sheet>.toml with sensible defaults to the target ref (--ref / --commit-to, default the default branch). Useful as a first-step before bulk-importing records. The working tree is not written. When the target branch does not exist yet, it is created with a root commit holding only the config — the way to start a data branch:
gitsheets init users --commit --branch data
gitsheets init users
gitsheets init users --path='${{ slug }}'
gitsheets init users --schema=./schemas/user.schema.json
Defaults:
root = <sheet>(the sheet name)path = '${{ id }}'
Flags:
--path <tpl>— override the path template.--schema <file>— embed a JSON Schema file under[gitsheet.schema]. The schema is validated through the same loader the runtime uses; an invalid schema aborts before the transaction commits.--force— overwrite an existing.gitsheets/<sheet>.toml. Without--force, init refuses to clobber.--commit— the explicit spelling of what init does (commit the config); reads well in bootstrap scripts.
gitsheets infer <sheet> ¶
Scan every record in the sheet and write a conservative starter [gitsheet.schema] block into .gitsheets/<sheet>.toml. The committed schema captures observed types per field, plus minimum/maximum hints for numeric fields and items.type for arrays. Fields present in every record are listed under required.
gitsheets infer users
Existing root, path, and any non-schema fields.<name>.sort rules are preserved. The result is a starting point — review and tighten (add pattern, format, etc.) before relying on it.
gitsheets migrate-config <sheet> ¶
Convert a pre-v1.0 [gitsheet.fields] config to a v1.0 [gitsheet.schema] config in one transaction.
gitsheets migrate-config orders
Migration table (matches specs/behaviors/validation.md):
| Pre-v1.0 field | v1.0 placement |
|---|---|
type: 'number' \| 'string' \| 'boolean' |
[gitsheet.schema.properties.<name>].type |
enum: [...] |
[gitsheet.schema.properties.<name>].enum |
default: <value> |
[gitsheet.schema.properties.<name>].default |
sort: ... |
[gitsheet.fields.<name>.sort] (unchanged) |
trueValues: [...], falseValues: [...] |
Warning to stderr — move to CSV-ingest helper |
gitsheets merge <theirs> ¶
Sheet-aware merge (spec): record files changed on both sides since the merge base are merged field by field and written in canonical form, so a merged repo never carries a mix of serializations. Non-record files merge the way git merges them.
gitsheets merge import # into the default branch
gitsheets merge import --into published # into another branch
gitsheets merge import --dry-run # report the merged tree, move nothing
gitsheets merge import --prefer theirs # resolve field / delete-modify / blob conflicts for one side
Without --prefer, any conflict is listed on stderr (merge conflict: <path> (field <name> | delete-modify | blob)) and the command exits 1 with nothing written. Up-to-date and fast-forward cases are reported as such.
gitsheets merge-driver <base> <ours> <theirs> <path> ¶
A git merge driver so a plain git merge / rebase / cherry-pick gets the same record-level behaviour for files changed on both sides. Register it once per clone:
gitsheets merge --install-driver
# set: merge.gitsheets.name = "gitsheets record merge"
# set: merge.gitsheets.driver = "git sheet merge-driver %O %A %B %P"
# added: users/**/*.toml merge=gitsheets
# wrote /path/to/repo/.gitattributes — review and commit it
That sets the two merge.gitsheets.* git-config keys (per clone — git config isn’t versioned) and adds one .gitattributes line per sheet at HEAD, keeping whatever is already there; re-running adds nothing. Commit .gitattributes like any other file. By hand, it is the same three lines:
git config merge.gitsheets.name "gitsheets record merge"
git config merge.gitsheets.driver "git sheet merge-driver %O %A %B %P"
printf 'users/**/*.toml merge=gitsheets\n' >> .gitattributes
The driver resolves the sheet owning <path> from HEAD’s configs, field-merges the three files, and writes the canonical result over <ours> (exit 0). On a field conflict — or a path no sheet owns — it falls back to git merge-file, leaving git’s usual markers, and exits 1.
gitsheets contracts <subcommand> ¶
Manage schema contracts — vendored, immutable JSON Schema documents that sheets declare via implements and that compose into write-time validation. All writes land under .gitsheets/contracts/; sheet configs are never rewritten by tooling.
gitsheets contracts adopt <source> [--sheet <name>]... # vendor a document (file, https:// URL, or - for stdin)
gitsheets contracts verify [<sheet>]... # offline CI gate: documents + records all conform
gitsheets contracts test <sheet> --against <file-or-name> # structural check against any sheet (duck typing)
gitsheets contracts sync [<name>]... # re-fetch recorded sources, report drift — never rewrites
gitsheets contracts export <name> # vendored contract as interchange JSON on stdout
gitsheets contracts prune [--dry-run] [--yes] # remove vendored documents no sheet declares
adopt --sheet validates every existing record of the named sheet(s) against the would-be effective schema and refuses (tree untouched) until the data conforms. verify additionally warns when a declaring sheet’s local schema sets additionalProperties: false (which can reject contract-conforming records under allOf composition). See the contracts guide for the full workflow.
gitsheets submodule init <path> ¶
Set up a data submodule with no record checkout, so its records never sit in a working tree. Stages; never commits.
- With
--url <url>(a new submodule): adds the.gitmodulesentry (path,url,branch), clones into.git/modules/<path>without a checkout, writes the<path>/.gitpointer file, puts the submodule’sHEADon the branch, setssubmodule.<name>.ignore = dirty, and stages.gitmodulesplus the pointer. The branch is--branch, else the remote’s default branch; an empty remote needs--branchand the first write creates it. - Without
--url(an existing entry, e.g. a fresh clone of the superproject): fetches, putsHEADon the.gitmodulesbranch at the commit the superproject pins, and setsignore. Re-running is safe — an existing data branch is left where it is; a detachedHEADholding gitsheets writes (aftergit submodule update) is fast-forwarded onto the branch first, and a branch that diverged from it is refused, naming both commits.
--url reaches the remote before writing anything, so a failed clone leaves
.gitmodules and the git config untouched; re-run with a working URL.
gitsheets submodule init data --url git@github.com:org/app-data.git --branch main
gitsheets submodule init data # fresh clone of the superproject
ignore = dirty keeps the empty working tree from showing as
modified content; it also hides hand edits under <path>/. See
Headless data.
gitsheets commit ¶
Commit without writing a record: --allow-empty for an empty commit, --replace <tip> to
commit in place of the branch tip (which must be <tip>), or both. --message is required.
Every mutating command also takes --trailer 'Key: value' (or Key=Value),
--also-parent <commit> (an extra parent; gitsheets attaches no behaviour to it), and
--replace <tip>. These have no environment variable.
gitsheets --branch log commit --allow-empty --message 'cycle 1' --trailer 'Cycle-Id: 1'
gitsheets head ¶
The tip commit of the branch being read (--ref, default the default branch) as JSON:
hash, tree, parents, author, committer, subject, body, trailers. null on an unborn branch.
gitsheets push [--remote r] [--to <commit>] ¶
Push the default branch, or only up to --to (the tip or a first-parent ancestor), never
forced. Prints pushed <hash> or up-to-date <hash>.
Exit codes ¶
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Generic / unknown error |
| 2 | Argument-parsing error: unknown flag or command, missing positional, malformed --filter / --agg / --trailer / --attachment / --encoding value, or an invalid flag combination |
| 22 | ValidationError |
| 23 | AggregationError |
| 64 | ConfigError |
| 65 | RefError |
| 66 | NotFoundError |
| 67 | ContractError |
| 69 | TransactionError |
| 70 | IndexError |
Per specs/api/cli.md.
Error output ¶
Errors print to stderr in this shape:
gitsheets: ValidationError: record failed JSON Schema validation
code: validation_failed
issue: email: must match format "email" (json-schema)
An AggregationError names the sheet, the aggregate, and (for a rollup
partition) the partition:
gitsheets: AggregationError: min over mixed value kinds
code: aggregation_failed
sheet: transactions
aggregate: low
An argument error (exit 2) prints one line:
gitsheets: --agg n: sum needs a field (n=sum:<field>)