On October 31 I deleted the GitHub Actions workflow from this site's repo. The CI job had stopped running, and I didn't want to wait on it anyway. So now I run tests before git push in every repo I own, on my Mac, with one shared hook. If a check fails, the push stops and the code never leaves my machine.
It's two short shell scripts. One installs the hook, the other decides what to run. Below is how they work and what bit me while rolling them out to every repo.
Why I run tests before git push
CI tells you something broke after you've already shared it. A pre-push hook tells you before. For one person working across many repos, that order matters more than a nice dashboard.
It also matters because many of my pushes come from Claude Code, not from me typing. I run several sessions at once (I wrote about the side panel I built to keep up with them), and each one commits and pushes on its own. A hook is a rule an agent can't forget. My shared instructions tell every session to never push with --no-verify, and the hook does the rest.
The hook itself
Git runs a file called pre-push in a repo's hooks folder right before it sends anything. If that file exits with an error, git cancels the push.
Mine is three lines. A shebang, a comment that says who installed it, and one line that hands off to a shared script in my home folder, passing along whatever git gave it. Every repo points at the same script, so when I improve it once, every repo gets the change.
How it picks what to run
My repos use different stacks: Next.js sites, Android apps in Kotlin, a little PHP. I didn't want to write a hook per repo, so the shared script looks at the repo and takes the first match:
- A repo-specific command, if I've left one in the hooks folder for a repo where guessing is wrong.
- A check script in package.json, plus the end-to-end tests if check doesn't already include them.
- A check target in a Makefile.
- Otherwise, each of lint, typecheck, test, build and the end-to-end tests that the package.json has.
- For Android projects, Gradle's ktlint check, the unit tests and a debug build.
- For PHP, the composer lint and test scripts.
If it finds nothing, it says so and lets the push through. A repo of notes shouldn't be blocked because it has no tests.
It also reads the lockfile to pick npm, pnpm, yarn or bun, so I never configure that by hand.
On this site, check runs lint, the TypeScript typecheck, every test (including the database tests, which run against a local Postgres) and a production build. The hook then adds two end-to-end scripts: one opens every studio page at phone width and fails if anything scrolls sideways or the menu breaks, and one checks the pay and booking buttons on the pricing pages. All of that runs before every push.
The edge cases that bit me
A hook that runs on every push has to get the edges right, or I'd start resenting it.
- Deleting a branch. Git calls the hook for that too. There's nothing to check, so the script reads what git is pushing and exits early when every ref is a deletion.
- Uncommitted changes. The checks run on the working folder, not on the commit, so a stray edit can make a broken commit pass. The script prints a warning when the folder isn't clean.
- Worktrees. I keep one worktree per branch so parallel sessions never share a checkout. In a worktree, .git is a file, not a folder, and the hooks live in the main repo. The script asks git where the shared folder is instead of assuming.
- Java on a Mac. macOS has no system Java, so Android builds failed in the hook. The script now points at Homebrew's JDK 17 when nothing else is set.
- Repos that already had a hook. The installer keeps the old one as pre-push.bak instead of overwriting it. Repos whose hooks are tracked in git (Husky does this) get skipped and listed, so I can decide by hand.
The installer is safe to rerun. When I clone or start a repo, I run it once with that repo's path, and it's covered.
What I gave up, and what I got
I lost the green check mark on GitHub. I work alone, so it was mostly decoration.
What I got is faster. A failure shows up in the terminal where I'm already working, with the exact step that failed. And because the hook already ran a production build, I turned off preview builds for my Vercel projects (every app is its own project, sharing one domain). Merging to main starts a production build I already know passes.
There's one cost worth naming: a full check on this site takes a few minutes, and I wait for it on every push. I'd rather wait on my Mac than find out from a failed deploy.
This post went through the same hook before it reached you. The blog has a test that rejects any post the parser can't read, so a bad heading here would have stopped the push.
Try it in one repo
Pick your busiest repo, write a pre-push file that runs your test command, and make it executable. Push something broken on purpose and watch it stop. Once you trust it, move the logic into one shared script and point every repo at it.