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.
- Set a template directory:
git config --global init.templatedir '~/.config/git/templates'
- Create a directory for hooks:
mkdir -p ~/.config/git/templates/hooks
- Now we can add the hook under
~/.config/git/templates/hooks
directory, likepost-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: Framework to manage multi-language precommit hooks.
- husky & lint staged: npm package
Pre-commit framework
Global configuration
- Run
pre-commit init-templatedir ~/.config/git/templates
.
See some issues like Global hooks (core.hooksPath) for more details.
Language plugins
- Golang
- PHP
- Terraform
- antonbabenko/pre-commit-terraform
- Require
coreutils
forterraform_validate
on mac OS.
- Require
- antonbabenko/pre-commit-terraform
- Kubernetes
- Circle CI
- syntaqx/git-hooks
- Run
circleci config validate
- Run
- syntaqx/git-hooks
Last updated on