Skip to content

Instantly share code, notes, and snippets.

@Yengas
Created October 11, 2019 10:47
Show Gist options
  • Save Yengas/25ed42199b5657b9d4d9339b3acb8e15 to your computer and use it in GitHub Desktop.
Save Yengas/25ed42199b5657b9d4d9339b3acb8e15 to your computer and use it in GitHub Desktop.
# git commit with branch helper
gam () {
MESSAGE="$1"
TASK_ID=$(git branch | grep \* | cut -d ' ' -f2 | perl -l -ne '/[a-z]+\/([A-Z]+\-[0-9]+)($|=)/ && print $1')
if [ -z "$TASK_ID" ]; then
echo "task id not be found. branch examples: feature/RECO-01, feature/RECO-01=long-description"
echo "falling back to normal commit"
git commit -am "$MESSAGE"
elif [ -z "$MESSAGE" ]; then
echo "message could not be found. add a message to your commit."
else
git commit -am "$TASK_ID $MESSAGE"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment