Pre-commit hooks act on the developer machine before a commit is finalized, while pre-receive hooks enforce policy on the SCM server before a push is accepted. Used together, they create local prevention and centralized enforcement, which is the most reliable way to keep secrets out of shared repositories.
Where the Enforcement Boundary Actually Sits
Pre-commit and pre-receive hooks both intercept Git activity, but they sit on different sides of the trust boundary. A pre-commit hook runs on the developer workstation before the commit object is written into history, so it is best for fast local checks and immediate feedback. A pre-receive hook runs on the server after a push arrives, so it is the point where shared policy is enforced consistently for everyone.
That difference matters because local hooks are only as strong as the developer’s environment and willingness to run them, while server-side hooks can block content from entering the shared repository. In practice, the two are complementary rather than interchangeable.
Git Hooks and Pre-commit Security Guide covers the practical boundary conditions for hooks, including what they can enforce locally and where bypass risk starts to matter.
How the Two Hooks Change Developer Workflow
Pre-commit hooks are mainly about prevention at the moment of authoring. They are useful for formatting, linting, lightweight policy checks, and secret detection because they catch issues before the developer spends time creating or sharing a bad change. Their weakness is that they can be bypassed, misconfigured, or absent entirely on a machine that has not been set up correctly.
Pre-receive hooks are about control at the point of entry to the central repository. They are better for rules that must apply uniformly, such as blocking secrets, rejecting unsigned or malformed content, or enforcing repository-level policy. Because they run server-side, they do not rely on every developer using the same local tooling.
Push Protection Guide is the right companion when the question is really about how blocking secret disclosure works once content reaches a shared platform.
Why Using Both Is Stronger Than Picking One
In practice, the most reliable pattern is layered enforcement. Pre-commit catches mistakes early, reduces noise, and gives developers a fast repair loop. Pre-receive provides the final gate, which is what keeps policy from depending on local discipline, tool parity, or hope.
That layered model is especially important for secrets, tokens, and credentials. A developer may forget to run a local hook, may use a different client, or may copy changes into a path the local hook does not inspect. Server-side enforcement is what prevents those misses from becoming shared exposure.
Git Secret Scanning Guide explains how pre-commit, push protection, CI, and history scans fit together as a layered detection and prevention model.
Risk and Threat Considerations
The main risk is assuming that a local hook is a control instead of a convenience. If the local hook is the only barrier, a bypass, a misinstalled hook, or a maliciously altered developer environment can let sensitive material reach the repository.
Failure mechanism: The developer-side check never runs, is disabled, or is weaker than the server policy, so a secret, unsafe change, or prohibited content gets committed and then travels to a shared system where it is harder to remove.
Impact: The organisation gets inconsistent enforcement, higher exposure to secret leakage, and more expensive remediation because the bad content may already be replicated, indexed, or referenced by downstream tooling.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Non-Human Identity Top 10 addresses the attack and risk surface, while CIS Controls v8, NIST SP 800-53 Rev 5 and OWASP ASVS set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| CIS Controls v8 | CIS-5 — Account Management | Git hooks help enforce consistent access and change-control practices across users. |
| Recommendation — Use account and change controls to ensure only approved paths can introduce repository changes. | ||
| NIST SP 800-53 Rev 5 | AU-2 — Event Logging | Hook enforcement and bypass attempts are operational events worth recording for review. |
| Recommendation — Log hook decisions and bypass attempts so policy failures can be investigated quickly. | ||
| OWASP ASVS | V16 — Security Logging and Error Handling | Local and server-side checks should produce clear security-relevant failure handling. |
| Recommendation — Return clear, actionable validation failures when a hook rejects unsafe content. | ||
| OWASP Non-Human Identity Top 10 | NHI-02 — Secret Leakage | The question's repository-protection use case directly intersects with preventing secret exposure. |
| Recommendation — Block secrets both before commit and again at repository ingress to reduce leakage risk. | ||
Practitioner Guidance
What to verify: Treat pre-commit as a speed and quality control, not as the final safeguard. Verify that the same critical policy is enforced again on the server, because the server-side decision is what determines whether the repository actually accepts the change.
What good looks like: Developers get immediate feedback locally, but the central repository still rejects anything that violates policy. That combination reduces friction without relying on every workstation being perfect.
Common mistake: Teams often deploy pre-commit hooks and then stop there, which creates a false sense of coverage. If the server does not re-check the same class of issue, the control can be bypassed with very little effort.
Practitioner takeaway: Use pre-commit to catch problems early, but depend on pre-receive for enforcement that must survive client differences, bypasses, and inconsistent developer setups.
Related resources from NHI Mgmt Group
- What breaks when organisations rely on pre-commit hooks alone for secrets protection?
- How should security teams implement pre-commit hooks without treating them as a primary control?
- What do teams get wrong about IDE plugins and pre-commit hooks for code security?
- What is the difference between secrets scanning in pre-commit hooks and secrets management in the CI/CD pipeline?
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on November 19, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org