Member-only story
Top 10 Pre-Commit Hooks Every Repository Should Have
Hi everyone, welcome back. Today, I will be going over ten pre-commit hooks — checks that run automatically before a commit lands, catching problems while they are still on your machine instead of in a pull request or in production.
If you are newer to this, here is the idea. Git has a feature called hooks: scripts that run at certain points, like just before a commit is created. A pre-commit hook can inspect what you are about to commit and refuse if something is wrong. On its own that is awkward to set up — the scripts live in .git/hooks, which is not version controlled, so every person on the team has to configure it themselves and nobody does.
The pre-commit framework fixes that. You write one YAML file, commit it to the repository, and everyone runs the same checks. It handles installing the tools, running them only on changed files, and in many cases fixing the problem rather than just reporting it.
The examples throughout use files written to contain real problems, with the output each hook produces on them.
Getting Set Up First
Two commands, once per repository:
pip install pre-commit
pre-commit installThe second one writes the hook into .git/hooks/pre-commit. Then you add a…




