Git hooks are scripts that Git runs automatically at specific points in the commit or push lifecycle, letting teams enforce standards and automate checks without relying on developers to remember to run them manually.
A team adds a pre-commit hook that runs a linter and rejects the commit if there are style violations, catching formatting problems locally instead of letting them show up as failed CI checks minutes later.
#!/bin/sh
# .git/hooks/pre-commit
mvn -q checkstyle:check
if [ $? -ne 0 ]; then
echo "Checkstyle failed, commit aborted."
exit 1
fiA concise interview answer is
Git hooks run scripts automatically at points like commit or push, so a team can enforce linting, tests, or commit message standards without depending on developers remembering to do it manually. That catches problems early, before code even reaches CI.
Last updated: 16 July 2026
Previous question: How do you handle a situation where you accidentally committed sensitive information (like passwords) to a repository?
Next question: You made big changes to a file and want to go back to an earlier version without losing your current work. How would you do it?