Git hooks

Git hooks

July 24, 2020

Configurations

Template directory

See this article and this for details. Git template is the directory to gets copied everytime when a repository is created or cloned.

  1. Set a template directory: git config --global init.templatedir '~/.config/git/templates'
  2. Create a directory for hooks: mkdir -p ~/.config/git/templates/hooks
  3. Now we can add the hook under ~/.config/git/templates/hooks directory, like post-commit file which is executable.

Pre-commit

I think pre-commit hook is most useful hook of all git hooks. For example, in order to check the code is good to commit by running lint tools. Due to this, there are some useful tools to configure hooks easily.

Pre-commit framework

Global configuration

  1. Run pre-commit init-templatedir ~/.config/git/templates.

See some issues like Global hooks (core.hooksPath) for more details.

Language plugins

Last updated on