What are the type of git hooks?

Technology CommunityCategory: GitWhat are the type of git hooks?
VietMX Staff asked 3 years ago

Git hooks can be categorized into two main types:

  • Client-Side Hooks
  • Server-Side Hooks

Client-Side Hooks:

  • These are hooks installed and maintained on the developers local repository and are executed when events on the local repository are triggered.
  • They are also known as local hooks.
  • They cannot be used as a way to enforce universal commit policies on a remote repository as each developer can alter their hooks.
  • Some client-side hooks are: 1. pre-commit 2. prepare-commit-msg 3. commit-msg 4. post-commit 5. post-checkout 6. pre-rebase
  • From the list above, the first 4 hooks are executed from top to down hierarchy. The last 2 hooks allows to perform some extra actions or safety checks for git checkout and git rebase commands.
  • All of the pre- hooks let you alter the action that’s about to take place, while the post- hooks are used only for notifications.

Server-Side Hooks:

  • These are hooks that are executed in a remote repository on the triggering of certain events.
  • These hooks can act as a system administrator to enforce nearly any kind of policy for a project like rejecting a commit based on some rule.
  • The server-side hooks are listed below based on the execution order: 1. pre-receive 2. update 3. post-receive
  • The output from server-side hooks are piped to the client’s console, so it’s very easy to send messages back to the developer.