Git post commit hook
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
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 .git/hooks/
.
Make sure 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
2
3
4
5
6
#!/bin/sh
# Filepath - .git/hooks/post-commit
# Mirror master in gh-pages.
git checkout gh-pages
git merge master
git checkout master
Further references about git hooks
- Git-scm.com Customizing-Git-Git-Hooks
- Githooks.com by Matthew Hudson