Skip to content

Instantly share code, notes, and snippets.

@naclsn
Created January 6, 2023 15:57
Show Gist options
  • Save naclsn/f1343d8ff09dbebe036e20c129c05ed9 to your computer and use it in GitHub Desktop.
Save naclsn/f1343d8ff09dbebe036e20c129c05ed9 to your computer and use it in GitHub Desktop.
Add branch name to commit message.
#!/bin/sh
# prepend branch name to message
# aborts on empty message
# not applied for branch `main`
# by-passe by prefixing with '!!'
# (in which these are removed)
two=`head -c 2 "$1"`
case ${two:-#} in
\#*) : >"$1"; exit 1;;
\!!) sed -i 1s/^..// "$1"; exit 0;;
esac
branch=`git rev-parse --abbrev-ref HEAD`
[ main = $branch ] || sed -i 1s/^/$branch:\ / "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment