.git/hooks

Table of Contents

Git Hooks tutorial

ls .git/hooks
applypatch-msg.sample
commit-msg.sample
fsmonitor-watchman.sample
post-update.sample
pre-applypatch.sample
pre-commit.sample
pre-push.sample
pre-rebase.sample
pre-receive.sample
prepare-commit-msg.sample
update.sample

You can modify these files and remove .sample extension to activate hooks.

There are two kinds of hooks:

Local Hooks
  • pre-commit
  • prepare-commit-msg
  • commit-msg
  • post-commit
  • post-checkout
  • pre-rebase
Server-side Hooks
  • pre-receive
  • update
  • post-receive

Git-managed(shared) hook scripts: copy or symlink them to .git/hooks discussion

Managing hooks under the repository is good to share the same scripts between developers. As we can't manage files under .git we should decided to copy or symlink scripts into .git/hooks.

In a git hook, is the working directory guaranteed to be within the git repository? discussion

Before Git invokes a hook, it changes its working directory to either the root of the working tree in a non-bare repository, or to the $GIT_DIR in a bare repository.