AcademyTimeline Architect: Mastering the Time MachineProtocol 9: Automated Sentinels

Module 9: Automating with Git Hooks

Git Hooks are scripts that run automatically every time a particular event occurs in a Git repository.

Step 1: The Pre-commit Hook

The pre-commit hook runs before you even type your commit message. It's the perfect place to run tests or check for "secrets" (like API keys) that shouldn't be committed.

Mission: Create and make the pre-commit hook executable. Run: touch .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit

Step 2: Adding Logic

You can add any shell script to this file. If the script exits with a non-zero code, the commit is blocked!

Mission: Add a simple echo message to your hook so you know it's working. Run: echo "echo 'Running security checks...'" > .git/hooks/pre-commit

booting...

Mission Control

Create a Pre-commit Hook

Expected Command

touch .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit

Preventing Secret Commits