0
0
Gitdevops~20 mins

Client-side vs server-side hooks in Git - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Git Hooks Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Difference between client-side and server-side Git hooks

Which statement correctly describes the main difference between client-side and server-side Git hooks?

AClient-side hooks run on the developer's machine before or after local Git actions; server-side hooks run on the remote repository server during push or receive events.
BClient-side hooks run only on the remote server to validate commits; server-side hooks run locally to check code style.
CClient-side hooks are used to enforce branch policies on the server; server-side hooks modify files on the developer's machine.
DClient-side hooks are triggered after pushing code to the server; server-side hooks run before committing locally.
Attempts:
2 left
💡 Hint

Think about where the hooks execute: on your computer or on the remote server.

💻 Command Output
intermediate
1:30remaining
Output of a client-side pre-commit hook script

Given this simple pre-commit hook script in .git/hooks/pre-commit that prevents commits with TODO comments:

#!/bin/sh
grep -q 'TODO' **/*.py && echo 'Commit blocked: TODO found' && exit 1 || exit 0

What will happen if you try to commit a Python file containing a TODO comment?

AThe commit will succeed without any message.
BThe commit will be blocked and the message 'Commit blocked: TODO found' will be shown.
CThe script will cause a syntax error and the commit will fail silently.
DThe commit will succeed but print 'Commit blocked: TODO found' as a warning.
Attempts:
2 left
💡 Hint

Consider what grep -q does and the exit codes in shell scripts.

🔀 Workflow
advanced
2:00remaining
Server-side hook to reject pushes to main branch

You want to prevent anyone from pushing directly to the main branch on the remote Git server. Which server-side hook should you configure and what should it do?

AConfigure the <code>pre-push</code> hook on the client side to reject pushes to <code>main</code>.
BConfigure the <code>post-receive</code> hook to delete the <code>main</code> branch after the push completes.
CConfigure the <code>update</code> hook to allow all pushes except those to <code>refs/tags</code>.
DConfigure the <code>pre-receive</code> hook to check if the pushed ref is <code>refs/heads/main</code> and reject the push with a message.
Attempts:
2 left
💡 Hint

Think about which server-side hook runs before accepting pushed commits.

Troubleshoot
advanced
1:30remaining
Why is a client-side commit-msg hook not running?

You created a commit-msg hook script in .git/hooks/ to validate commit messages, but it does not run when you commit. What is the most likely reason?

AThe hook script is named <code>commit-msg.sh</code> instead of <code>commit-msg</code>.
BThe hook script is in the wrong directory; it should be in <code>.git/hooks/commit-msg/</code>.
CThe hook script is not executable (missing execute permission).
DGit does not support <code>commit-msg</code> hooks.
Attempts:
2 left
💡 Hint

Check file permissions for scripts in .git/hooks.

Best Practice
expert
2:30remaining
Best practice for sharing Git hooks across a team

What is the best way to ensure all developers on a team use the same Git hooks without manually copying scripts into each local .git/hooks directory?

AStore hooks in a version-controlled directory in the repository and configure Git to use that directory with <code>core.hooksPath</code>.
BAdd hook scripts to the <code>.git/hooks</code> directory and commit that directory to the repository.
CSend hook scripts by email to each developer to install manually.
DUse server-side hooks only and do not use client-side hooks.
Attempts:
2 left
💡 Hint

Think about how to version control hooks and configure Git to find them.