Question

Is there a way to have git warn you before finishing a commit, if the commit message does not contain a GitHub issue number?

Was it helpful?

Solution

You can enable the client-side git hooks available on a per repo basis at .git/hooks. Inside this subdirectory you may find a bunch of samples. Here's a description of the hooks and how to use them.

In this case I think that the most suitable hook is commit-msg and you can check if the file that holds the proposed commit log message contains a susbtring in the form #123. For that purpose you could use the following regular expression:

$(grep '^.*#([1-9][0-9]*).*$' $1)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top