Progress:
TIER 2 · MODULE 49· Intermediate

git hook

Small porcelain over the .git/hooks dir.

🎯 What & why

Thin porcelain over the .git/hooks directory: lists, runs, and otherwise pokes the repo's hook scripts. Useful when you want to invoke a hook manually instead of waiting for git to fire it.

🧠 Mental model

Hooks are just executable files in .git/hooks/ (or wherever core.hooksPath points). Git runs them at well-defined moments; git hook run is the manual trigger.

🛠️ Synopsis

git hook run [--ignore-missing] [--to-stdin=<path>] <hook-name> [-- <hook-args>]

# Hooks live in:
.git/hooks/<name>            # default location
$(git config core.hooksPath) # override (team-shared hooks dir)

# Common hooks (chmod +x to enable):
pre-commit, prepare-commit-msg, commit-msg, post-commit
pre-push, pre-rebase, post-checkout, post-merge
pre-receive, update, post-receive, post-update  (server side)

🎚️ Switches & options

FlagWhat it does
run <name>Execute the named hook as if git triggered it
--ignore-missingExit 0 if the hook isn't installed instead of erroring
--to-stdin=<file>Pipe file contents to the hook's stdin
-- <args>Pass remaining args to the hook
chmod -x .git/hooks/X⚠️ Disabling a hook by removing the +x bit; trivially reversible but easy to forget

📦 Subcommands

run — Run a named hook with the same env git would set up
git hook run pre-commit

💡 Use cases

🧪 Examples

Run the pre-commit hook now
git hook run pre-commit
Test commit-msg with a draft message
git hook run --to-stdin=draft.txt commit-msg draft.txt
Skip silently if hook missing
git hook run --ignore-missing pre-push
Point repo at a shared hooks dir
git config core.hooksPath .githooks

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.