1

When I am trying to run git commit -m 'message here' I am getting following error.

fatal: cannot exec '.git/hooks/prepare-commit-msg': Permission denied

This issue started after when I created a new partition on my ubuntu and cloned the repo in it.

Sushmit Sagar
  • 1,198
  • 2
  • 10
  • 24

1 Answers1

1

You'll need to make your file executable, the below code snippet will make the file executable for the owner, the group and the world:

$ chmod +x .git/hooks/prepare-commit-msg
Andreas Louv
  • 44,338
  • 13
  • 91
  • 116
  • 1
    Is the OP probably talking about an older version of git? With git 2.29.2 I'm getting `hint: The '.git/hooks/prepare-commit-msg' hook was ignored because it's not set as executable.` and `git commit` still succeeds. Or is it a shell-related issue, not git? – terrorrussia-keeps-killing Dec 21 '20 at 14:58
  • 2
    @fluffy I can see that a check for non executable files was introduced in 2.13 see the commit https://github.com/git/git/commit/940283101ce87250cf31a592730386f5061e1286 I'm not sure which version OP is running. – Andreas Louv Dec 21 '20 at 15:13
  • 3
    The message was added later, in 2.14.3 https://github.com/git/git/commit/f805a00a396ee91599902cebe55620b2a4c813b9 – Andreas Louv Dec 21 '20 at 15:15
  • I can see this phenomenon too, and I'm wondering where this hook is originating from, what creates it and why it is missing the step of making it executable. Any idea? – Hendrik Wiese Oct 13 '21 at 05:23
  • @HendrikWiese You created the file, either by creating it manually, by having used the `init.templatedir`, (`--templatedir`) when cloning / initializing a repository. Or if you have run a program that creates these hooks. – Andreas Louv Oct 13 '21 at 09:31
  • I think it's the latter. I'm just wondering which program that might be... I'm using GitKraken as git UI, IntelliJ IDEA/PyCharm as IDE... one of them _might_ be the culprit... – Hendrik Wiese Oct 13 '21 at 12:41
  • Or `chmod +x .husky/pre-commit` if you are using `husky`. – SalahAdDin Mar 13 '22 at 10:16