CLI Quickstart
The CLI is the easiest way to try Graft. graft sql opens an ordinary physical
SQLite worktree file, while repository commands use Graft’s control-plane
service directly. No SQLite extension or repository PRAGMA transport is
involved.
Create A Repository
Section titled “Create A Repository”-
Create a scratch app data directory.
Terminal window mkdir app-state-democd app-state-demo -
Initialize Graft.
Terminal window graft initThis creates
.graft/. It does not create a default SQLite database. -
Write SQLite data.
Terminal window graft sql --db data.sqlite "CREATE TABLE notes(id INTEGER PRIMARY KEY, body TEXT);"graft sql --db data.sqlite "INSERT INTO notes(body) VALUES ('first note');" -
Inspect status.
Terminal window graft statusdata.sqliteappears as an unstaged SQLite database snapshot.At this point it is still a normal SQLite file. Graft reads it only when a repository command needs to inspect or stage the path.
-
Commit the first app-state version.
Terminal window graft add --allgraft commit -m "seed notes" -
Change the database and add an app file.
Terminal window graft sql --db data.sqlite "INSERT INTO notes(body) VALUES ('second note');"mkdir -p attachmentsprintf 'draft\n' > attachments/readme.txt -
See how Graft classifies paths.
Terminal window graft status --jsonPath entries include
kindandstorage, so apps can render database snapshots and files differently. -
Commit and inspect a row diff.
Terminal window graft add --allgraft commit -m "add second note and attachment"graft diff --rows HEAD~1 HEAD data.sqlite -
Restore the database from the latest commit.
Terminal window graft sql --db data.sqlite "DELETE FROM notes;"graft restore --source HEAD -- data.sqlitegraft statusThe final status should be clean.
Run SQL From Stdin
Section titled “Run SQL From Stdin”If no SQL argument is passed, graft sql --db <path> reads stdin:
cat <<'SQL' | graft sql --db data.sqliteCREATE TABLE IF NOT EXISTS notes(id INTEGER PRIMARY KEY, body TEXT);INSERT INTO notes(body) VALUES ('hello from stdin');SELECT * FROM notes;SQLBranch App State
Section titled “Branch App State”Branch and merge commands operate on the repository discovered from the current directory:
graft switch maingraft --db data.sqlite merge feature/searchgraft merge --continue -m "merge feature/search"switch materializes the tracked worktree paths without a database selector.
Pass --db to merge when it should open that SQLite database for row-aware
analysis; finishing the repository merge does not need it.