How to create a global git commit hook by Matt Venables
1 Enable git templates (This tells git to copy everything in ~/.git-templates to your per-project .git/ directory when you run git init):
git config --global init.templatedir '~/.git-templates'
2 Create a directory to hold the global hooks:
mkdir -p ~/.git-templates/hooks
3 Write your hooks in ~/.git-templates/hooks. For example, here's a post-commit hook (located in ~/.git-templates/hooks/post-commit):
#!/bin/sh
# Copy last commit hash to clipboard on commit
git log -1 --format=format:%h | pbcopy
# Add other post-commit hooks
4 Make sure the hook is executable.
chmod a+x ~/.git-templates/hooks/post-commit
5 Re-initialize git in each existing repo you'd like to use this in:
git init
NOTE if you already have a hook defined in your local git repo, this will not overwrite it.
This is why you would use githooks. If there is something you should do on every pull or every commit, then you definitely should be using githooks to automate that.
One thing that I can't stress enough when I am working with large organizations is that people are really, really good at one thing: making mistakes. Good automation practices help resolve this, and while you cannot automate everything, you certainly can automate almost everything.