E-mail : support@tech2now.in

How to Restriction git push in GitHub without JIRA ID

Git Git Hub git commit gir rebase git status git init

Set up a pre-push hook: In your local Git repository, navigate to the .git/hooks directory. Create a new file named pre-push and make it executable (chmod +x pre-push.sh. This hook script will be executed before every push.

Edit the pre-push hook script: Open the pre-push file in a text editor and add the following code

#!/bin/bash

remote=”$1″
url=”$2″

while read -r local_ref local_sha remote_ref remote_sha; do
#Extract the JIRA ID from the commit message
commit_message=$(git log –format=%B -n 1 “$local_sha”)
jira_id=$(echo “$commit_message” | grep -oE ‘[A-Z]+-[0-9]+’)

#Check if the JIRA ID is present
if [[ -z $jira_id ]]; then
echo “Error: Commit message must contain a JIRA ID.”
exit 1
fi
done

exit 0

Save the script:.

Jira id formate should be XXX-234 or XXX-123