Skip to content

Instantly share code, notes, and snippets.

@dominic-rossi
Created July 13, 2017 22:41
Show Gist options
  • Save dominic-rossi/74e9ca9d48988117f900c38eaab1ed86 to your computer and use it in GitHub Desktop.
Save dominic-rossi/74e9ca9d48988117f900c38eaab1ed86 to your computer and use it in GitHub Desktop.
Add the current branch name to the beginning of commit messages
#!/bin/sh
branch_name=$(git symbolic-ref -q HEAD)
branch_name=${branch_name##refs/heads/}
branch_name=${branch_name:-HEAD}
firstLine=$(head -n1 $1)
if [ -z "$firstLine" ] ;then #Check that this is not an amend by checking that the first line is empty
sed -i "1s@^@$branch_name: \n@" $1 #Insert branch name at the start of the commit message file
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment