# Git Hooks Architecture & Deployment **Notes:** Learn what a Git hook is, where it runs, and two ways of deploying an application with a `git push`. **Recommended reading** - [Version Control with Git](/2026/course/201-git/) - [Collaborating with Git](/2026/course/203-git-collaborating/) --- ## What is a Git hook? A **program that Git runs** when an action happens. - Found **by its name** in the `.git/hooks` directory - Run only if it is **executable** **Notes:** A hook can be any kind of executable file: a shell script, a Python script, a compiled program. The `.sample` files Git puts in `.git/hooks` are examples: their extension keeps Git from running them. --- ### Hooks for most actions | Hook | Runs | | :------------- | :------------------------ | | `pre-commit` | Before a commit | | `commit-msg` | After writing the message | | `pre-push` | Before sending a push | | `pre-receive` | Before taking a push | | `post-receive` | After taking a push | **Notes:** The `git help hooks` command lists every hook, with when each one runs. --- ## Where does a hook run?
**Notes:** A server-side hook runs on the server, but what it prints is sent back to the terminal of whoever pushed, on lines that start with `remote:`. --- ### Before or after the action - `pre-...` runs **before**: if it fails, the action **does not happen** - `post-...` runs **after**: the action **has already happened** **Notes:** A hook fails when it ends with a non-zero exit status. A failing `pre-receive` hook makes the server refuse the push. --- ### Hooks are not cloned A hook is **not part of the repository's history**. A clone brings the commits, **never the hooks**. **Notes:** This is on purpose: otherwise, cloning a repository from the Internet could make your computer run someone else's program the next time you commit. --- ## Deploying with a push Push to the **server**, or push to **GitHub** with a **webhook** --- ### Pushing to the server
**Notes:** [Heroku](https://www.heroku.com), one of the first cloud platforms, deploys this way, with `git push heroku main`. --- ### What is a webhook? An **HTTP request** that a service sends to another one **when something happens**. A webhook is **not a Git hook**. --- ### Pushing to GitHub, with a webhook
**Notes:** The push never reaches the platform. You connect the platform to your GitHub repository once, and it registers its webhook with GitHub for you.
GitHub