Git hooks are scripts that run automatically at certain points in the Git workflow. Which statement best explains why hooks help automate workflows?
Think about how automation removes the need to remember manual steps.
Git hooks run scripts automatically at specific events like commit or push. This lets you enforce checks or trigger tasks without doing them manually, automating parts of your workflow.
Given a pre-commit hook script that checks for TODO comments and blocks commit if found, what will be the output if a TODO comment exists in the staged files?
#!/bin/sh if git diff --cached | grep -q 'TODO'; then echo 'Commit blocked: TODO comments found.' exit 1 fi exit 0
Look for the condition that triggers the message and exit code.
The script searches staged changes for 'TODO'. If found, it prints the message and exits with code 1, blocking the commit.
Arrange the following Git hooks in the order they run during a typical git push operation.
Think about when commits happen versus when push starts and ends.
First, pre-commit runs before commit, then post-commit after commit. Before pushing, pre-push runs, and after push finishes, post-push runs.
You created a pre-commit hook script in .git/hooks/ but it does not run when committing. What is the most likely cause?
Check file permissions for scripts to run automatically.
Git requires hook scripts to have execute permission. Without it, the script is ignored.
What is the best way to share Git hooks across a team to ensure everyone uses the same automated checks?
Think about how to keep hooks versioned and easy to install for all.
The .git/hooks/ directory is not versioned by Git. Storing hooks in the repo and copying them with a setup script ensures consistency and easy updates.