We always want to speed up our workflows, right? Of course, automation is the best way to do that.
Git hooks are scripts that Git executes before or after events such as: commit, push, and receive.
In my words, Hooks is like an event trigger, After you did some git operation it'll trigger some events.
There are two types of git Hooks.
1.) Client side (Local PC)
2.) Server side (Remote Server)
#!/bin/sh => For shell Scripts
#!/usr/bin/env python => For Python
#!/usr/bin/env ruby => For Ruby
applypatch-msg
pre-applypatch
post-applypatch
pre-commit
prepare-commit-msg
commit-msg
post-commit
pre-rebase
post-receive
pre-commit
prepare-commit-msg
commit-msg
post-commit
./post-receive
# check if app is running fine otherwise execute few commands manually
sudo forever stopall
GIT_WORK_TREE=/home/ec2-user/project
export GIT_WORK_TREE
git checkout -f
cd /home/ec2-user/project
sudo npm install
forever start app.js
Hooks
post-receive | git-receive-pack on the remote repo | This is run on the remote when pushing after the all refs have been updated. It does not take parameters, but receives info through stdin in the form of "<old-value> <new-value> <ref-name>". Because it is called after the updates, it cannot abort the process. |