Git HooksIntermediate
1Question 1 of 1
bashHow do Git Hooks automate pre-commit linting and testing?
Explanation & Concept
Git hooks are scripts placed in `.git/hooks/` (or managed via Husky) that run automatically at key points in the Git workflow (e.g. `pre-commit`, `commit-msg`, `pre-push`).
If the hook script exits with a non-zero status code, Git aborts the commit or push.
Code Example
bash
#!/bin/sh
# .husky/pre-commit
echo "Running automated pre-commit checks..."
# Run linter and type-checker
npm run lint || exit 1
npm run type-check || exit 1
echo "Pre-commit checks passed successfully!"How It Works & Key Takeaways
Pre-commit hooks prevent developers from accidentally pushing unlinted or broken code to remote repositories.
Mock Test · 1 Questions · Optional
Ready for Reverting vs Resetting?
Take a quick test to evaluate yourself, or move straight to the next module.
Intermediate3 questions