Challenge - 5 Problems
Pre-Push Hook Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this pre-push hook script?
Given this simple pre-push hook script, what will be the output when you try to push?
Git
#!/bin/sh echo "Running pre-push checks..." exit 1
Attempts:
2 left
💡 Hint
Remember that exit 1 in a hook stops the push.
✗ Incorrect
The script prints the message and exits with status 1, which blocks the push and shows the message.
🧠 Conceptual
intermediate1:30remaining
What is the main purpose of a pre-push hook in Git?
Choose the best description of what a pre-push hook does.
Attempts:
2 left
💡 Hint
Think about when the hook runs relative to the push action.
✗ Incorrect
A pre-push hook runs before the push to check conditions and can block the push if needed.
❓ Troubleshoot
advanced2:30remaining
Why does this pre-push hook not block the push?
This pre-push hook script is supposed to block pushes if tests fail, but pushes always succeed. Why?
Git
#!/bin/sh ./run_tests.sh exit 0
Attempts:
2 left
💡 Hint
Check the exit code of the hook script.
✗ Incorrect
The hook script exits with 0 regardless of test results, so Git allows the push.
🔀 Workflow
advanced1:30remaining
In which directory should you place a pre-push hook script?
Where do you put a pre-push hook script so Git runs it automatically?
Attempts:
2 left
💡 Hint
Git looks for hooks in a specific folder inside the .git directory.
✗ Incorrect
Git runs hooks placed in the .git/hooks directory with the exact hook name.
✅ Best Practice
expert3:00remaining
What is the best way to share a pre-push hook with your team?
You want all team members to use the same pre-push hook. What is the best practice?
Attempts:
2 left
💡 Hint
Git does not track .git/hooks folder contents.
✗ Incorrect
Since .git/hooks is not versioned, committing the hook script and providing a setup script ensures consistent hooks.