Skip to main content

Claude/ChatGPT Prompt to Build Git Pre-Commit Quality Gates

Set up Git hooks for code quality enforcement: linting, formatting, commit message validation, and secret detection before every commit.

Vul de plaatshouders in

Edit the values, then copy your finished prompt.

Jouw Prompt
prompt.txt

                                

What this prompt does

This prompt sets up a comprehensive Git hooks system for a [language]/[framework] project using your [hook_manager]. It wires a pre-commit hook that runs [linter] on staged files only, auto-formats with [formatter] and re-stages the changes, scans for secrets with [secret_scanner], and blocks [anti_patterns] before anything reaches a commit. The whole system is tuned to stay fast enough that the team keeps it switched on.

It works because catching a leaked credential or an unformatted file locally beats fixing it in review. The commit-msg hook validates against your [commit_convention], a pre-push hook runs [pre_push_checks], and a post-merge hook reinstalls dependencies when the lockfile changes. Crucially, it keeps total hook time under [max_time] seconds via staged-files-only scope, parallel execution, and caching. It includes a documented skip mechanism for genuine emergencies and mirrors the same checks in CI so a local bypass still gets caught downstream.

When to use it

  • You want to catch lint, format, and secret issues before they land, not in review
  • Standardising commit messages against a [commit_convention] like Conventional Commits
  • Blocking [anti_patterns] such as stray console.log, debugger, or test .only
  • Running heavier [pre_push_checks] (type-check, unit tests) before code leaves a machine
  • You need hooks fast enough that the team won't disable them
  • Mirroring local checks in CI so someone can't quietly bypass the hooks

Example output

You get all config files plus setup instructions: [hook_manager] configuration, a pre-commit hook running [linter] and [formatter] on staged files with re-staging, secret scanning via [secret_scanner], anti-pattern checks for [anti_patterns], a commit-msg validator for [commit_convention], a pre-push hook running [pre_push_checks], a post-merge dependency-install hook, parallelised execution tuned to stay under [max_time] seconds, a documented emergency skip, and a CI mirror of the same checks.

Pro tips

  • Keep the linter and formatter scoped to staged files; running them on the whole project is the main reason hooks get slow and disabled
  • Set [max_time] to a number developers will tolerate (around ten seconds) and rely on parallel execution and caching to hit it
  • List real [anti_patterns] for your stack (console.log, debugger, hardcoded localhost) so the checks block what actually causes problems
  • Treat [secret_scanner] as a safety net, not a guarantee; rotate any credential that ever reaches a commit regardless of the scan result
  • Validate commit messages against [commit_convention] so downstream automation like semantic versioning has clean input to work from
  • Document when the skip mechanism is acceptable so it's used for genuine emergencies, not as a routine shortcut around the gates
  • Use the post-merge hook to reinstall dependencies when the lockfile changes, so teammates don't run against a stale node_modules after a pull
  • Mirror the hooks in CI so a local bypass still fails the pipeline and nothing slips through to the main branch

Frequently Asked Questions

Will running these hooks slow down every commit?
The pre-commit hooks run only on staged files and use parallel execution to stay under your `[max_time]` target, around ten seconds. Scoping to staged files rather than the whole project is the key to keeping commits fast enough that the team keeps the hooks enabled.
Does it actually catch leaked secrets?
It runs `[secret_scanner]`, such as gitleaks, on staged changes to flag credentials before they are committed. Treat this as a strong safety net rather than a guarantee, and always rotate any secret that does slip through, since scanners can miss novel patterns.
Can I bypass the hooks in an emergency?
Yes, the setup includes a documented skip mechanism for genuine emergencies. Because the same checks are mirrored in CI, a local bypass still gets caught in the pipeline, so skipping locally does not let bad changes reach the main branch unchecked.
Does it enforce a commit message format?
Yes, the commit-msg hook validates messages against your `[commit_convention]`, such as Conventional Commits. This keeps history consistent and is what enables downstream automation like semantic versioning and grouped changelog generation.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

Meer in Git & GitHub Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support