Skip to content

Instantly share code, notes, and snippets.

@manoj2411
Created June 19, 2020 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manoj2411/c93a4dff1dbebb460f0f68d70741c275 to your computer and use it in GitHub Desktop.
Save manoj2411/c93a4dff1dbebb460f0f68d70741c275 to your computer and use it in GitHub Desktop.
Checks git message every time and ensure that the message is starting with the defined format. Useful where you need Jira-ID or something similar in start of the message
#!/bin/sh
#
# save this file with this name and mark it executable `chmod +x .git/hooks/commit-msg`
commit_desired_format='(ZA-\d+|GH-\d+|merge)'
error_msg="Aborting commit. Commit message is missing ('ZA-XXX') or ('GH-XXX') or 'merge'"
if ! grep -iqE "$commit_desired_format" "$1"; then
echo "$error_msg" >&2
exit 1
fi
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment