Skip to content

Instantly share code, notes, and snippets.

@aristidesneto
Created September 22, 2023 16:08
Show Gist options
  • Save aristidesneto/6cac19d4e223afd83ff07c2b8633d6a1 to your computer and use it in GitHub Desktop.
Save aristidesneto/6cac19d4e223afd83ff07c2b8633d6a1 to your computer and use it in GitHub Desktop.
Change commit message by branch name. Ex: feature/1234 => [ DSO-1234] - My commit message
#!/bin/bash
BRANCH_NAME=$(git symbolic-ref --short HEAD)
TICKET="${BRANCH_NAME##*/}"
EXP='^[0-9]+$'
if [ -n "$BRANCH_NAME" ] && [[ $TICKET =~ $EXP ]]; then
sed -i.bak -e "1s/^/[ DSO-$TICKET ] - /" $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment