It is a good idea to prefix the git commit message with story id for
better traceability. For the same reason, it is also nice to prefix
the branch name with story id as well, even though git branch is more
short lived than commit messages.
However, forcing developers manually prepending the story id to
commit messages is not guaranteed to work. As always, automation is
the way to go.
It turns out that it is pretty easy to write a git commit-msg hook to
prepend the story id automatically if it is already present in the
branch name. Assuming that the format of the branch name is:
where N represents an arbitrary digit. The following code snippet can be
set up as git commit-msg
hook to
automatically prepend “FOO-NNN: “ to your commit message if there
wasn’t one yet.
Great! Now we just need to remember to always name our branch correctly
:) If you really wanna have a bit of assurance about that
, we can have a simple git extension to verify the format of the
branch name before it is created. Let’s say we want our branch name to
be compliant to the aforementioned format, the extension would look
something like this:
For more info please take a look at the code on
Github.