About
hooks 1) is an extension system of Git to execute executable file implemented by external party (ie not Git) that run at specified steps of a command.
Location
There are two groups:
- Client-Side Hooks: Scripts that are executed on the local computer (committer/dev computer)
- Server-Side Hooks: Scripts that are executed on the remote computer (server)
Client
- Commit
- Email (You submit patches review by sending a email. (Maintainers receive them and are responsible for applying them).
- merging,
- checking out,
- rebasing,
- rewriting,
- and cleaning repos.
Server
- Push:
- Pre-receive - check
- Post-receive - deploy
- Update: Check on branch?
Workflows / List
Push
Hooks triggered during a push
- pre-receive,
- update,
- post-receive,
- post-update,
- push-to-checkout
The working directory is the git dir.
Others
The whole list is available online here
Location
All hooks are stored in the hooks subdirectory of the git directory location that contains already examples.
List of examples:
ls -1 .git/hooks
applypatch-msg.sample*
commit-msg.sample*
fsmonitor-watchman.sample*
post-update.sample*
pre-applypatch.sample*
pre-commit.sample*
pre-merge-commit.sample*
pre-push.sample*
pre-rebase.sample*
pre-receive.sample*
prepare-commit-msg.sample*
push-to-checkout.sample*
sendemail-validate.sample*
update.sample*
The location can be changed via the core.hooksPath configuration
git config core.hooksPath
Execution
Working Directory
The working directory is
- GIT_DIR in a bare repository
- the root of the working tree in a non-bare repository.
- with the exception of push hooks which are always executed in GIT_DIR.
Arguments
Hooks can get their arguments via:
- the environment,
- the command-line arguments,
- and stdin.
Copy Hooks from server
git init may copy hooks to the new repository, depending on its configuration. See the TEMPLATE DIRECTORY section