Published on

Making the Git pre-commit hook work on macOS

Last Modified on
Last modified on
Authors
Making the Git pre-commit hook work on macOS
Photo by Glauber Forquato on Pexels

I was setting up husky for a project I am working on, and for some reason, my husky pre-commit hook was “not executable” by default. When I made a commit, I got the following back in my VS Code Integrated Terminal:

hint: The '.husky/pre-commit' hook was ignored because it's not set as executable.
hint: You can disable this warning with git config advice.ignoredHook false.

I don’t remember ever having had that problem in the past, but apparently this is a very old issue. In the thread on the husky repository on Github, someone shared the following solution:

chmod ug+x .husky/*

I delved deeper into this issue, and actually found the person’s solution on stackoverflow.

So far everything works beautifully. If anything does change, I will update this post. I think I did the same thing as someone within the stackoverflow thread did. It is the following:

I got my solution. I added pre-commit file manually so it was not
executable(644). I removed pre-commit file and added using this command yarn
husky add .husky/pre-commit that makes pre-commit file executable(755) and works
fine (on) any new branch.

So, to solve this type of issue, we have to avoid adding manual hook file and
use this command yarn husky add .husky/<hookname> to add.

I used npm, so if you are also using npm, replace yarn add with npm i. - refer to Husky needs to make executable for every new branch