A Git hook is an executable script that runs automatically when an event occurs in a repository. Client-side hooks can reject invalid commits before creation; server-side hooks can validate pushed commits. This fail-fast control supports GitOps and APIOps when version control is the project’s source of truth. section 8.8
Implement hooks as lightweight governance controls:
- Use a pre-commit hook to require a commit message containing a JIRA issue reference such as DEV-1234. section 8.8
- Keep hooks fast, reliable, documented, and non-mutating unless the committer explicitly consents. section 8.8
- Distribute client-side hooks deliberately because cloning a repository does not install them; a hook package manager can manage installation and execution. section 8.8
#!/bin/bash
commit_msg_file=$1
# Read the commit message file
commit_msg=$(cat "$commit_msg_file")
# Pattern to match Jira issue reference (DEV-XXXX)
Pattern="DEV-[0-9]{4}"
# Check if the commit message contains the Jira issue reference
if [[ ! $commit_msg =~ $pattern ]]; then
echo "Error: Commit message does not contain a valid
Jira issue reference in the format DEV-XXXX."
echo "Please include a Jira issue reference in your commit message."
exit 1
fi
Use the Bash example as a template for reading the commit-message file, matching DEV-XXXX, and rejecting nonconforming messages. section 8.8

