Skip to content

Instantly share code, notes, and snippets.

@avivl
Created December 22, 2015 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avivl/5147c671a7ef1e010c7a to your computer and use it in GitHub Desktop.
Save avivl/5147c671a7ef1e010c7a to your computer and use it in GitHub Desktop.
prepare-commit-msg
#!/bin/bash
branch_name=$(git symbolic-ref -q HEAD | awk '{split($0,a,"/"); print a[length(a)]}' | awk '{split($0,a,"_"); print a[1]}')
first_line=$(head -n1 $1)
if [ -z "$first_line" ] ;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