How to Automatically Format SQL in a Git Pre-Commit Hook
By Sharon Ben-Moshe · August 2, 2026 · 2 min read
Sharon Ben-Moshe is the founder of sqlfmt, a browser-based SQL formatter and validator with misspelled-keyword suggestions across PostgreSQL, MySQL, SQLite, SQL Server, and BigQuery.
A pre-commit hook that formats and validates SQL catches bad queries before they ever reach a pull request — earlier and cheaper than CI. Here's a working setup using the sqlfmt API.
Quick answer
A Git pre-commit hook can format and validate every staged .sql file automatically by sending each file's contents to a formatting API and blocking the commit on syntax errors — catching mistakes seconds after they're written instead of minutes later in CI.