# Git Hooks

URL: https://softwaredictionary.org/terms/git-hooks
Category: Version Control
Last updated: 2026-09-30

In short: Git hooks are scripts that Git runs automatically at certain points, such as before a commit or a push, to check code, enforce rules, or automate tasks.

## What are Git hooks?

Git hooks are scripts that Git runs automatically when specific events happen in a repository. For example, a `pre-commit` hook runs just before a commit is created, and a `pre-push` hook runs before changes are sent to a remote. They are commonly used to run linters, formatters, or quick tests so problems are caught before they reach anyone else.

Hooks live in the `.git/hooks` folder of each repository, and a hook is simply an executable file named after the event, such as `pre-commit` or `commit-msg`. If a hook like `pre-commit` exits with a non-zero status, Git stops the operation, so a failing check can block a bad commit. Because the `.git` folder is not part of the tracked project files, hooks are not shared when someone clones the repository; teams commit them to a regular folder and point Git to it with `core.hooksPath`, or use a hook manager tool.

Think of hooks as the checklist a pilot runs before takeoff: the flight only continues once every item passes. Client-side hooks run on a developer's machine, while server-side hooks such as `pre-receive` run on the Git server and can reject pushes that break team rules, such as commit messages without a ticket number.

Git hooks are sometimes confused with CI/CD pipelines. Local hooks give fast feedback, but any developer can skip them with `git commit --no-verify`, so they cannot guarantee quality on their own, which is why teams use hooks for speed and CI as the final gate. Git hooks are also different from webhooks, which are HTTP requests a hosting platform sends to other services when something happens in a repository.

## Key takeaways

- Hooks are scripts that Git runs automatically on events like commit, merge, or push.
- A non-zero exit code from a hook like `pre-commit` cancels the operation.
- Hooks in `.git/hooks` are not shared on clone, so teams use `core.hooksPath` or a hook manager.
- Client-side hooks can be skipped with `--no-verify`, so CI remains the final check.
- Server-side hooks such as `pre-receive` can enforce rules for everyone.

## Example: A pre-commit hook that runs the linter and tests

```bash
#!/bin/sh
# .githooks/pre-commit: runs automatically before every commit

echo "Running linter and tests..."
npm run lint || exit 1   # a non-zero exit code blocks the commit
npm test     || exit 1

# Enable this hooks folder for the repository (run once):
#   chmod +x .githooks/pre-commit
#   git config core.hooksPath .githooks
```

## Frequently asked questions

**How do I skip a Git hook?**

Add `--no-verify` to the command, for example `git commit --no-verify` or `git push --no-verify`. Use it sparingly, because it bypasses the checks your team relies on.

**How do I share Git hooks with my team?**

Commit the hook scripts to a folder in the repository, such as `.githooks`, and have each developer run `git config core.hooksPath .githooks`. Many teams automate this with a hook manager that installs the hooks along with the project's dependencies.

**What is the most common Git hook?**

The `pre-commit` hook is the most widely used, typically to run formatters, linters, and fast tests on the files being committed.

---

Software Dictionary: https://softwaredictionary.org/ · https://softwaredictionary.org/llms.txt
