DEV Community

How to customise your git commit message

Sebastian on March 25, 2017

1. Add default template directory git config --global init.templatedir '~/.git-templates' Files and directories in the defa...
Collapse
 
dmerejkowsky profile image
Dimitri Merejkowsky

Nice :)

By the way, since a few git versions, you can also use the hooksPath config variable.

So for instance you could have prepare-commit-msg under version control, in a hooks directory and then tell people to update the .git/config file to look like:

[core]
hooksPath = hooks/
Enter fullscreen mode Exit fullscreen mode

An other possibility is for you to write the same kind of config code in
~/.config/git/config and have your prepare-commit-msgscript in just one place ;)

Hope this helps.

Collapse
 
bgannin01 profile image
Brian Ganninger

I'm a fan of using commit templates as well to take our commit messages to the next level. robots.thoughtbot.com/better-commi...

Collapse
 
edwin_r_c profile image
Edwin Ramirez

Getting this error after following every step by the letter.

$ git commit
.git/hooks/prepare-commit-msg: 2: .git/hooks/prepare-commit-msg: Syntax error: "(" unexpected (expecting "fi")

Collapse
 
ebud7 profile image
Sebastian

Hi Edwin

please make sure that #!/bin/sh is on top of your script file.

I added this here as well, thanks for reaching out!

Collapse
 
edwin_r_c profile image
Edwin Ramirez

Hi, sorry for not giving back any feedback. For some reason this didn't work on Linux Mint. Buuuuut it worked perfectly on Mac OS Sierra. I think, maybe, I missed that last hint:
"You might have to set the permissions on your new hook. (sudo chmod 775 .git/hooks/prepare-commit-msg)".
Thanks a lot!

Collapse
 
pzelnip profile image
Adam Parkin

Hmm, I followed the steps, and on git commit I don't see the branch name in vi. I did do a git init in my repo.

Collapse
 
ebud7 profile image
Sebastian

Sounds like a permission problem. Please have a look at the last hint, that is solving your problem. ✌🏻