All Tools View Categories About Contact Privacy

Git Hooks Generator

Pick a moment — before commit, after merge, before push — configure the checks, and get an annotated executable hook script, generated locally in your browser.

Runs entirely in your browser — hook templates ship with the page and nothing is uploaded.

Rejects empty messages, over-long subjects, and (with Conventional Commits) subjects that do not match type(scope): subject.

A complete, annotated starting point tuned for its moment in the workflow. Read the comments at the top before changing behaviour.

1. Save the script into a versioned hooks/ folder.

2. Make it executable: chmod +x hooks/pre-commit

3. Point Git at the folder: git config core.hooksPath hooks

4. Commit the folder so every clone enforces the same rules.

pre-commit — checks on staged content before the commit.

prepare-commit-msg — annotates the message before the editor opens.

commit-msg — validates the finished message.

post-commit — after the commit lands.

post-checkout — after switching branch or checking out files.

post-merge — after a successful merge or pull.

pre-push — gate before the remote receives anything.

pre-rebase — guard before history is rewritten.

post-rewrite — after rebase / amend rewrites.

pre-merge-commit — right before the merge commit.

0
lines
0
bytes
hook
hooks/pre-commit

    

About Git Hooks Generator

Git hooks are the automation layer between “you are about to commit” and the commit actually landing. A two-line pre-commit that calls git diff --check catches the whitespace noise that pollutes every diff review; a commit-msg hook that enforces the subject length keeps history readable; a pre-push hook that runs the tests stops broken code from ever reaching the remote. The catch that makes teams avoid them is the tiny barrier of writing a correct shell script for each stage, plus the fact that hooks live in .git/hooks and are not versioned unless you wire up a hooks/ directory with core.hooksPath. This generator removes the writing part — you pick the moments and the checks, and it emits a finished, executable script.

The tool produces scripts for the ten standard hooks. The pre-commit is the workhorse: it can reject whitespace errors, block files that still contain merge-conflict markers, scan staged content for obvious secret patterns (tokens, private keys, AWS-style keys), run a lint or test command you supply, and remind you to keep scripts executable. Every failing check exits non-zero — silently in normal operation — and Git aborts the commit with the specific problem listed. A successful run prints a short summary line per check, so the happy path is also visible.

The commit-msg hook enforces message discipline at the moment it really matters. Configure the maximum subject length, and the hook rejects a first line that exceeds it before Git accepts the commit. Turn on Conventional Commits and it validates the type(scope): subject shape, warning for unknown types and rejecting malformed punctuation, with the type list and scope rules configurable. Pre-push wraps your full test command and stops any push whose work is not green. The remaining hooks — prepare-commit-msg, post-commit, post-checkout, post-merge, pre-rebase, post-rewrite, pre-merge-commit — get complete, annotated starting points tuned for their moment in the workflow.

Output is a pragmatic artifact, not a toy. Scripts are POSIX-friendly (bash or /bin/sh at your choice), use set -euo pipefail, print colored status only when attached to a terminal, and include the chmod +x and core.hooksPath instructions as comments on the first lines. Every script ends with a note that git commit --no-verify bypasses the hooks, so an emergency never becomes a panic. Everything executes in your browser; the assembled script is ready to drop into a hooks/ directory and commit to the repository.

Features

  • Ten standard hooks — pre-commit, prepare-commit-msg, commit-msg, post-commit, post-checkout, post-merge, pre-push, pre-rebase, post-rewrite, pre-merge-commit.
  • Whitespace check — rejects trailing whitespace and conflict markers via git diff --check.
  • Conflict marker scanner — fails when resolved or unresolved <lt;<lt; >gt;> markers are detected in staged content.
  • Secret scanning — blocks obvious token, key and private-key patterns in staged content.
  • Lint or test command — runs your command and gives a clear failure message when it is not configured.
  • Executable reminder — nudges that staged scripts must stay executable.
  • Subject length limit — the commit-msg hook rejects over-long first lines (50/72 aware).
  • Conventional Commits validation — optional strict type(scope): subject enforcement with a configurable type list.
  • Pre-push tests — wraps any command to block pushes when the suite fails.
  • bash or /bin/sh — pick the interpreter and the script is written accordingly.
  • Executable and shareable — download includes chmod +x note and core.hooksPath tip.
  • Nothing uploaded — templates are bundled with the page and generation runs offline.

How to Use

  1. Pick the hook type — pre-commit, commit-msg, pre-push or one of the remaining seven.
  2. Choose the shell — bash (feature-rich) or /bin/sh (minimal) as the shebang.
  3. Configure the checks — whitespace, conflict markers, secrets, lint/test commands, subject limits, Conventional Commits.
  4. Generate the script — read the annotated output and the run summary.
  5. Download the file and place it in a versioned hooks/ directory.
  6. Make it executable — chmod +x hooks/pre-commit — and run git config core.hooksPath hooks.
  7. Commit the hooks folder so every clone enforces the same rules.

Examples

Example 1 — Quality gate. pre-commit with whitespace, conflict markers and a test command: any staged whitespace error or lingering conflict marker blocks the commit, and npm test must pass first.

Example 2 — Secret guard. pre-commit with the secret scanner enabled: a staged line containing AKIA-style keys or BEGIN RSA PRIVATE KEY fails the commit before anything leaves the machine.

Example 3 — Message discipline. commit-msg with a 72-character subject limit and Conventional Commits on: feat(auth): handle token expiry passes, while Add stuff and FEAT: x are rejected with a message explaining the expected shape.

Example 4 — Deployment guard. pre-push wrapping npm test and the build: every push must be fully green or Git refuses to upload.

Example 5 — Minimal team baseline. a shared hooks/ folder with only the whitespace pre-commit and a non-empty commit-msg, wired with core.hooksPath, so every member starts consistent.

Benefits

  • No shell-script debt — annotated scripts instead of a five-line attempt.
  • Consistent team rules — hooks commit to the repo and apply to every clone.
  • Cleaner diffs — whitespace and secret slips die before they reach review.
  • History stays readable — subject limits and Conventional Commits enforced at the source.
  • Quick to skip, easy to share — --no-verify documented, core.hooksPath wiring included.
  • Nothing uploaded — script generation runs entirely in the browser.
  • Offline friendly — the tool works with no network connection at all.

Frequently Asked Questions

What are Git hooks?
Small scripts that Git runs automatically at defined moments of a workflow: before a commit, after a commit, before a push, and so on. They live in the .git/hooks directory of a clone but are not versioned — teams share them via a hooks/ folder plus a command to point Git at it, or a tool like core.hooksPath.
How do I generate one with this tool?
Pick the hook type, choose your shell, tick the checks you want (whitespace errors, conflict markers, secret patterns, lint/test commands, subject length, Conventional Commits), and press Generate. The script is assembled in your browser — copy or download it into the hooks directory.
Where do hook files go?
By default in .git/hooks of a clone — but to share them, keep the scripts in a versioned hooks/ folder and run git config core.hooksPath hooks so every clone uses them. The file must be executable (chmod +x hooks/pre-commit), and the script must exit non-zero to block the action.
Which hooks does the generator cover?
pre-commit, prepare-commit-msg, commit-msg, post-commit, post-checkout, post-merge, pre-push, pre-rebase, post-rewrite and pre-merge-commit — the full set a typical team needs, with sensible checks for the important ones.
How can I temporarily skip a hook?
Pass --no-verify to the git command, for example git commit --no-verify or git push --no-verify. This is useful in emergencies but should not become the default habit. The generated scripts print a gentle reminder about this on the way out.
Is my data sent anywhere?
No. The generator runs entirely in your browser: the hook templates and check blocks are bundled with the page and nothing is uploaded. It works offline and is safe for proprietary work.
What does a pre-commit hook check?
The generated pre-commit can fail on whitespace errors (git diff --check), stray conflict markers (<<<<<<< / ======= / >>>>>>>), files with suspicious secret patterns (API keys, tokens), and can run an arbitrary lint or test command you provide before letting the commit through.
What does a commit-msg hook check?
That the commit message is not empty, that the subject stays within your chosen length limit, and optionally that it matches the Conventional Commits format type(scope): subject. The script can also be configured to allow or require a scope.