What are Git Hooks?

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

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





Discover More
Heroku

App hosting on with dynos where: An application is a collection of source code written in one language. A dyno is a lightweight Linux container that...
What is the Git Repository (Directory) ?

This page is the notion of repository and how it's implemented in Git. The git repository is a subdirectory named .git called also GIT_DIR that contains all repository files. It contains : commit...



Share this page:
Follow us:
Task Runner