Skip to content

Instantly share code, notes, and snippets.

@cravecode
Created September 24, 2015 16:28
Show Gist options
  • Save cravecode/99b40192c959eb4c0aa9 to your computer and use it in GitHub Desktop.
Save cravecode/99b40192c959eb4c0aa9 to your computer and use it in GitHub Desktop.
Adds a GitHub Issue number to a commit message based on the branch name. I.e.: branch-name-123
#!/bin/bash
branchPath=$(git symbolic-ref -q HEAD) #Somthing like refs/heads/myBranchName
branchName=${branchPath##*/} #Get text behind the last / of the branch path
issueNumber=$(echo "$branchName" | grep -Po "\-\d+$" | grep -Po "\d+")
# If there was a issue number in the branch name, append it to the commit message.
if [ -n "$issueNumber" ]; then
# Write the issue number to the commit message.
echo "Issue: #$issueNumber" >> $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment