Skip to content

Instantly share code, notes, and snippets.

@MatteoGioioso
Created July 22, 2019 06:49
Show Gist options
  • Save MatteoGioioso/615596ca1ad11c4e08919acf2473ec1f to your computer and use it in GitHub Desktop.
Save MatteoGioioso/615596ca1ad11c4e08919acf2473ec1f to your computer and use it in GitHub Desktop.
How to automatically prepend git commit with a branch number tag
#!/bin/bash
#Does not work if executed as sh
#Copy this commit script into prepare-commit-msg
BRANCH_NAME=$(git branch 2>/dev/null | grep -e ^* | tr -d ' *')
IFS='-' read -r -a array <<< "$BRANCH_NAME"
if [ -n "$BRANCH_NAME" ]; then
echo " (#$array) $(cat $1)" > $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment