Git Hooks - bounswe/2021SpringGroup12 GitHub Wiki
What is a Git Hook?
A git hook is a script that Git runs before or after pre-determined events such as commit, push, merge. They come with Git pre-installed and does not require anything else to run. You just write your script, place it to the correct directory and Git runs them every time that script is triggered.
Event List:
- applypatch-msg
- pre-applypatch
- post-applypatch
- pre-commit
- prepare-commit-msg
- commit-msg
- post-commit
- pre-rebase
- post-checkout
- post-merge
- pre-receive
- update
- post-receive
- post-update
- pre-auto-gc
- post-rewrite
- pre-push
How to write and run a Git Hook?
Every git hook is basically a script that runs on specific conditions and some of them specific parameters to them. This means to use them to full effect we need to study and learn about them. But even with some basic scripting skills you can increase your productivity greatly.
Git hooks can be found in ./.git/hooks
folder of every git repository you created. After you wrote your git hook script you need to name it accordingly and place it under the ./.git/hooks
folder. But you need to remember that git hooks run only locally, and Git never recognizes the .git
folder. So to share your git hooks with your team you need to place them under another folder to push it to the origin and then provide them with the instructions to run them properly.