• Git hooks are scripts that execute before or after a particular git event
  • Some useful hooks,
    • Pre-commit hooks
    • Pre-push hooks
    • Pre-receive hooks - executed on the remote when someone tries to push to it
    • Post-Receive hooks - triggered post accepting a push

Example: Pre-commit hook for a Gradle project

#!/bin/bash
# This script runs tests before pushing changes to the remote repository.
 
./gradlew test
 
# Check the exit status of the tests
if [ $? -ne 0 ]; then
    echo "Tests failed. Aborting push."
    exit 1
fi