GIT hooks

GIT hooks provide a hook-in point for GIT operations that allow users to modify the default GIT behavior.
To add a git hook, navigate to the root of your project and find the .git directory. Inside the .git directory are examples of git hooks.
The file names describe the operation which the hook executes on. Examples shown below:

Commit message check

This GIT hook fires before the GIT commit operation runs. If the commit message does not conform to the expected Regular expression, the commit operation is aborted. This code should be placed in the ./git/hooks/commit-msg file.

1
2
3
4
5
6
7
8
9
#!/bin/sh

# Check if commit message has "[BugFix] ..." or "[Feature] ..."
commit_msg_regex="^\[BugFix|Feature\]\s\w"
if ! grep -iqE $commit_msg_regex "$1"; then
echo "Commit message invalid!" >&2
exit 1
fi
exit 0