Add A Prepare Commit Message To Customize Git Commits
If you work with any agile software or Github issues it is sometimes useful to prepend your commit message with a reference to the ticket or issue so commits can be associated with a work item. Using a prepare-commit-msg allows you with the correct branch to automatically prepend a git commit with the ticket/issue reference.
If you create a branch that is in reference to a Github issue, Github will automatically link back to that Github issue. If you use some other software you can update the Github settings under “Integrations” -> “Autolink references”
So if you have a branch that is named gh-#143-update-all-the-things
with a prepare-commit-msg
in your .git/hooks directory
any git commit could automatically have [gh-#143]
prepended to it! Check this example prepare-commit-msg
to see how this could work.
If you’re using something like pre-commit you could write a quick Python script to accomplish the same with this configuration
The following python logic could be used:
Read more about it here