Skip to content

Instantly share code, notes, and snippets.

@melizeche
Created July 27, 2022 21:18
Show Gist options
  • Save melizeche/2296b9c48809918bd863abb5a5021b6b to your computer and use it in GitHub Desktop.
Save melizeche/2296b9c48809918bd863abb5a5021b6b to your computer and use it in GitHub Desktop.
Better commit messages
# BRANCH_PREFIX will match everithing before the first underscore so if your branch name
# is ESGCA-9999_my_awesomefeature and your commit message is 'Fixes Changes Rabbits'
# your "final" commit message will be: 'ESGCA-9999: Fixes Changes Rabbits'
COMMIT_MSG_FILE=$1
BRANCH_PREFIX=$(git branch | grep '*' | sed 's/* //' | cut -d _ -f 1)
echo "$BRANCH_PREFIX: $(cat $COMMIT_MSG_FILE)" > "$COMMIT_MSG_FILE"
# Copy this file in the .git/hooks/ directory of your local repo and make it executable `chmod +x prepare-commit-msg`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment