Like every other version constrol systems, Git has a method to execute custom scrips when particular actions occur. We are calling it Git Hooks.
How git hook works
Every Git repository has a
.git/hooks folder. Where you can add/update these
scrips as whenever you need to. So Git will execute these scripts when
particular actions occur.
Post commit hook is invoking by
git commit. It takes no parameter,
and is invoked after a commit is made.
Real world example
Following post-commit hook is useful if you are managing
Github Project Pages.
We have to place this post-commit file under
post-commit file has execute permisson. This hook will fire when you
commit changes to the master branch, and sync master branch changes to gh-pages.
1 #!/bin/sh 2 # Filepath - .git/hooks/post-commit 3 # Mirror master in gh-pages. 4 git checkout gh-pages 5 git merge master 6 git checkout master