Commit Hooks
Learn more about Git hooks here.
Why Use Git Hooks?
Without automated checks, simple issues like linting errors can slip into the codebase, causing pipeline failures and unnecessary “fix-up” commits. By enforcing checks at commit or push time, we keep the commit history cleaner and ensure code quality from the start.
Why Pre-commit?
By default, Git hooks live only on the local machine and aren’t shared with others. This means each developer would need to set them up manually. Pre-commit solves this problem by allowing you to define hook configurations in a shared .pre-commit-config.yaml
file. Once committed to the repository, these configurations ensure every contributor runs the same hooks.
Despite the name, pre-commit can manage multiple hook types (such as pre-push
). Learn more about pre-commit.
Setting Up
Install pre-commit
Install the hooks
The Oakestra repository includes a.pre-commit-config.yaml
file. To set up hooks that run before pushing changes, run:
We chose pre-push to give developers flexibility. They can commit freely, fix linting issues before pushing, and avoid messy commit histories.
For more configuration details, visit the official pre-commit documentation.
Contributing Code
When you’re ready to push your changes:
- Perform
git push
as usual. - The configured
pre-push
hooks will run automatically, checking your code. - If issues are found, the push will be aborted so you can fix them before retrying.
By integrating pre-commit hooks into our workflow we ensure consistent code quality and a cleaner commit history.