Skip to content

Instantly share code, notes, and snippets.

@zidizei
Created June 11, 2020 19:09
Show Gist options
  • Save zidizei/de80c29a5df5fa0f8e3e73a8c850956e to your computer and use it in GitHub Desktop.
Save zidizei/de80c29a5df5fa0f8e3e73a8c850956e to your computer and use it in GitHub Desktop.
Prefixes git commit messages with the current branch's ticket number.
# prefixes git commit messages with the current branch's ticket number, e.g.
# feature/TICKET-123-description => git commit -m "TICKET-123 ..."
function gcmb() {
pat='[A-Za-z]+\/([A-Za-z]+[-_][0-9]+)[-_]'
branch=$(git rev-parse --abbrev-ref HEAD)
[[ $branch =~ $pat ]]
if [[ -z "$1" ]];
then
git commit -m "${match} " --edit
else
git commit -m "${match} ${1}"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment