What is a git hook? A git hook is a script that git executes before or after certain events, such as commit, push, or receive.

These hooks allow you to automate tasks and enforce policies in your git workflow.

  1. Pick an git event - for example pre-push
  2. Run bunch of commands - linters, tests
  3. If there is non-zero status abort - nothing happens
  4. Run git command - git push will do the push
  5. List of all available events ls .git/hooks

Pre-push setup

  1. create file .git/hooks/pre-push
  2. put commands here you would like to run, start with echo "It works!"
  3. run git command even without any commits: git push
  4. enjoy
🫵 If you enjoyed this article you can join my newsletter to get dose of weekly craftsmanship
    Unsubscribe anytime.