Git & GitHub Interview Question #127
What is the difference between client-side and server-side Git hooks?
Security, Team Workflows, Troubleshooting & Senior Git/GitHub Scenarios Senior Advanced
Quick Interview Answer
Client-side hooks run on a developer's machine during operations such as commit or push. They are useful for fast feedback but cannot be trusted as the only enforcement mechanism because users can omit, change, or bypass local hooks.
Detailed Explanation
Client-side hooks run on a developer's machine during operations such as commit or push. They are useful for fast feedback but cannot be trusted as the only enforcement mechanism because users can omit, change, or bypass local hooks.
Server-side hooks run on the Git server during receive operations and can enforce repository-wide policies. On hosted platforms such as GitHub, repository rules, protected branches, required checks, and GitHub Actions commonly provide centralized enforcement instead of custom server hooks.
Code Example
# Client-side example
.git/hooks/pre-commit
# Central enforcement on GitHub commonly uses:
# - branch protection / rulesets
# - required status checks
# - pull-request reviews