Skip to content

Instantly share code, notes, and snippets.

@timgthomas
Last active June 20, 2018 20:41
Show Gist options
  • Save timgthomas/5da411424a92a608ec12f750eb816267 to your computer and use it in GitHub Desktop.
Save timgthomas/5da411424a92a608ec12f750eb816267 to your computer and use it in GitHub Desktop.
Jira Issue–Aware Commit Function
# Usage:
# APP-1337 $ commit 'foo'
# > 'APP-1337: foo'
function commit {
local message=$1
local branch=$(git symbolic-ref HEAD)
local regex="([A-Z]+-[0-9]+)"
if [[ $branch =~ $regex ]]
then
git add -A && git commit -m "${match[1]}: ${message}" # zsh
# git add -A && git commit -m "${BASH_REMATCH[1]}: ${message}" # bash
else
git add -A && git commit -m "${message}"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment