Skip to content

Instantly share code, notes, and snippets.

@Sonare
Sonare / prepare-commit-msg
Last active November 13, 2022 22:29 — forked from l0ser140/prepare-commit-msg
Git hook adds JIRA issue to commit text if found it in branch name
#!/bin/sh
#
# git prepare-commit-msg hook for automatically prepending an issue key
# from the start of the current branch name to commit messages.
# check if commit is merge commit or a commit ammend
if [ $2 = "merge" ] || [ $2 = "commit" ]; then
exit
fi
ISSUE_KEY=`git rev-parse --abbrev-ref HEAD | grep -o "[A-Z0-9]\+-[0-9]\+"`
@Sonare
Sonare / pre-commit
Last active November 13, 2022 22:27
forbid commiting into master branch
#!/bin/sh
#
git rev-parse --abbrev-ref HEAD | grep -v -E "^master$" > /dev/null
if [ $? -ne 0 ]; then
echo "Current Branch is master"
exit 1
fi