Skip to content

Instantly share code, notes, and snippets.

@konstantindenerz
Last active May 14, 2020 05:02
Show Gist options
  • Save konstantindenerz/9c0cd960f9dd86fd6a1decdf6b98631b to your computer and use it in GitHub Desktop.
Save konstantindenerz/9c0cd960f9dd86fd6a1decdf6b98631b to your computer and use it in GitHub Desktop.
Use git hook to assign issue from branch name to commit message
#!/bin/sh
BRANCH_NAME=$(git symbolic-ref --short HEAD)
ISSUE_ID=$(echo $BRANCH_NAME | grep -o '[M|m][F\|f]-[0-9]*')
if [ -n "$ISSUE_ID" ]; then
sed -i.bak -e "1s/$/ [$ISSUE_ID]/" $1
fi
@konstantindenerz
Copy link
Author

konstantindenerz commented Sep 27, 2019

Place the file in /myproject/.git/hooks folder and make it executable chmod +x /myproject/.git/hooks/prepare-commit-msg.

Sample

branch name: feature/MF-42-bubu
commit message (before): foobar
commit message (after): foobar [MF-42]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment