Pre-Commit and Pre-Push Checks
What you'll learn: How to catch integration problems on your own machine before they break the build for your entire team.
Why Local Validation Matters
Continuous Integration relies on everyone pushing clean, working code to mainline. But what if you accidentally commit broken code, failing tests, or code that doesn't match your team's standards? The CI server will catch it—but only after you've pushed, triggering a build failure that blocks everyone else.
Pre-commit and pre-push checks are local gatekeepers that run automated validations on your machine before code even leaves your workstation. Think of them as a bouncer at a club: they verify your code meets minimum standards before letting it through the door.
Pre-Commit Checks
These run automatically when you attempt to commit code locally. Common checks include:
- Code formatting (linters, formatters)
- Basic syntax validation
- Fast unit tests
- Security scanners for secrets or credentials
Because they run frequently, pre-commit checks must be fast—typically under 10 seconds.
Pre-Push Checks
These run when you attempt to push commits to the remote repository. Since pushing happens less frequently than committing, you can afford slightly longer validations:
- Full unit test suite
- Static analysis
- Build verification
- Integration tests (if reasonably fast)
The Safety Net Analogy
Think of these checks as spell-check before sending an important email. You could rely on the recipient to catch your typos, but catching them yourself first is faster, less embarrassing, and more professional.
Most teams use tools like Git hooks to automate these checks—scripts that Git runs at specific moments in your workflow.
Key Takeaway: Pre-commit and pre-push checks catch problems locally before they break the shared build, maintaining CI's fast feedback loop and protecting team productivity.