4

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.

2

3 Answers 3

9

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
7
  • 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? Commented Dec 21, 2020 at 14:58
  • 2
    @fluffy I can see that a check for non executable files was introduced in 2.13 see the commit github.com/git/git/commit/… I'm not sure which version OP is running. Commented Dec 21, 2020 at 15:13
  • 3
    The message was added later, in 2.14.3 github.com/git/git/commit/… Commented Dec 21, 2020 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? Commented Oct 13, 2021 at 5: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. Commented Oct 13, 2021 at 9:31
1

For me, chmod +x for those git hooks did not help and I had to remove the file (move it to {filename}.bak).

I suppose this isn't a great solution, though.

1

For me I was getting the error fatal: cannot exec '.git/hooks/pre-push': Permission denied.

Applying Andreas's answer to this error message, I tried $ chmod +x .git/hooks/pre-push, and that fixed it. The subsequent commit and push commands went through successfully.

Apparently such fatal: cannot exec ... : Permission denied errors involving both git hooks can be resolved in the same way.

1

Not the answer you're looking for? Browse other questions tagged or ask your own question.