Skip to content

Instantly share code, notes, and snippets.

@warrenca
Created January 18, 2016 03:36
Show Gist options
  • Save warrenca/120845f3a481e3b083c5 to your computer and use it in GitHub Desktop.
Save warrenca/120845f3a481e3b083c5 to your computer and use it in GitHub Desktop.
Auto-add git branch on commit
#!/bin/sh
# This file must be executable
# chmod u+x .git/hooks/prepare-commit-msg
BRANCH_NAME=$(git symbolic-ref --short HEAD)
if [ -n "$BRANCH_NAME" ] && [ "$BRANCH_NAME" != "master" ]; then
# use ~ instead of / to accomodate branch names with forward slash
# e.g. branch name "user/feature-name-"
sed -i.bak -e "1s~^~[$BRANCH_NAME] ~" $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment