Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kmwalsh/a9138fda09d3d43d26f364a659054e08 to your computer and use it in GitHub Desktop.
Save kmwalsh/a9138fda09d3d43d26f364a659054e08 to your computer and use it in GitHub Desktop.
automatically prepend ticket number to commit message
* mv .git/hooks/commit-msg.sample .git/hooks/commit-msg
* chmod ug+x .git/hooks/commit-msg
paste the desired script into commit-msg
#!/bin/sh
# branch structure of `something/####-something`
ticket=$(git symbolic-ref HEAD | awk -F"[/-]" '{print $4}')
if [ -n "$ticket" ]; then
echo $ticket":" "$(cat $1)" > $1
fi
#!/bin/sh
# branch structure of `SOMETHING-####-SOMETHING`
ticket=$(git symbolic-ref HEAD | awk -F"[--]" '{print $2}')
if [ -n "$ticket" ]; then
echo $ticket":" "$(cat $1)" > $1
fi
#!/bin/sh
# branch structure of `something/something/SOMETHING`
ticket=$(git symbolic-ref HEAD | awk -F "/" '{print $NF}')
if [ -n "$ticket" ]; then
echo $ticket":" "$(cat $1)" > $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment