0
0
Gitdevops~20 mins

pre-push hook in Git - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pre-Push Hook Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2: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
APush is blocked with message: pre-push hook failed
BPush is blocked with message: Running pre-push checks...
CPush succeeds silently with no output
DPush succeeds but prints Running pre-push checks...
Attempts:
2 left
💡 Hint
Remember that exit 1 in a hook stops the push.
🧠 Conceptual
intermediate
1:30remaining
What is the main purpose of a pre-push hook in Git?
Choose the best description of what a pre-push hook does.
AIt runs before pushing to validate or block the push
BIt automatically merges branches before pushing
CIt runs after the push completes to notify the user
DIt deletes remote branches after pushing
Attempts:
2 left
💡 Hint
Think about when the hook runs relative to the push action.
Troubleshoot
advanced
2: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
AGit hooks cannot block pushes
BThe run_tests.sh script is not executable
CThe script always exits with 0, so push is never blocked
DThe hook file is not named correctly
Attempts:
2 left
💡 Hint
Check the exit code of the hook script.
🔀 Workflow
advanced
1: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?
A.git/hooks/pre-push
Broot directory of the project
Cany directory named hooks anywhere
D.git/pre-push
Attempts:
2 left
💡 Hint
Git looks for hooks in a specific folder inside the .git directory.
Best Practice
expert
3: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?
AUse a global Git hook configured on each developer's machine
BAsk each member to manually create the hook in their .git/hooks folder
CPut the hook script in the root directory and rely on Git to find it automatically
DCommit the hook script inside the repository and add a setup script to copy it to .git/hooks
Attempts:
2 left
💡 Hint
Git does not track .git/hooks folder contents.