The problem: you want JIRA ticket number in commit descriptions and possibly in the PRs. The solution: automate it.
Setup and usage:
- In the repository place the
prepare-commit-message.sh
file from this gist at.git/hooks/prepare-commit-message
(without.sh
extension).chmod +x
it. - Name branches like
ECA-333/remove-all-shit-and-add-good-code
. - Run
git config --global commit.template=~/.gitmessage
. Placegitmessage
from this gist at~/.gitmessage
(don't forget the starting dot). - Use
git commit
and wait for the editor, don'tgit commit -m
or gitx shennanigans to utilize it. - This way
ECA-333
will be grabbed out and used: (A) in the commit header and (B) below the commit description, formatted markdown-ready as a link to our JIRA. Example commit message: - Frequently a PR is just one commit. Pay some efforts to prepare a good commit message. Then PR and enjoy title of your commit grabbed as PR title, and body (and a markdown link to JIRA!) grabbed to PR description.
We need to go deeper:
- Now you possibly want to go further and don't manually copy it across the projects. I have a word to you.
- Run
git config --global init.templatedir=~/.git-templates
. - Place
prepare-commit-message
file from this gist at~/.git-templates/hooks/prepare-commit-message
(without.sh
extension).chmod +x
it. - All new repos will now have it.
- In an existing repo run
git init
. Don't worry, it won't crash anything, just reinitialize the hooks and other things.