Sushmit Sagar
Sushmit Sagar

Reputation: 1508

Git hook permission denied

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.

Upvotes: 4

Views: 14197

Answers (4)

GPrathap
GPrathap

Reputation: 7810

I was able to resolve this:

  1. Run the following command to check the file’s permissions:

    ls -l .git/hooks/prepare-commit-msg

  2. If the file is owned by a different user, you can change the ownership

    sudo chown $(whoami) .git/hooks/prepare-commit-msg

Upvotes: 0

mayowa_osibodu
mayowa_osibodu

Reputation: 109

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.

Upvotes: 0

tedro
tedro

Reputation: 31

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.

Upvotes: 1

Andreas Louv
Andreas Louv

Reputation: 47099

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

Upvotes: 9

Related Questions