git post-receive hook not running
Solution 1
In order for a Git hook to run, it needs to have permissions set to allow it to be executable. If a hook doesn't seem to be running, check the permissions, and make sure it's executable. If it isn't you can make all hooks executable like this:
chmod ug+x .git/hooks/*
...or if you want to make a single hook (eg. post-receive
) executable:
chmod ug+x .git/hooks/post-receive
(Thanks to this post)
Solution 2
I had this problem. I had a typo in my script filename.
post-recieve instead of post-receive
Solution 3
Seems GIT will NOT run the post-receive hook if there are no changes to the code base.
In my case,
The post hook was not getting executed, but the "push" operation kept returning the following message.
Everything up-to-date
So I just created an empty file in my code, did commit and then pushed to remote. On which the post-receive hook got executed.
Solution 4
I used MacBook and this helped in my situation:
chmod ug+x .husky/*
chmod ug+x .git/hooks/*
Admin
Updated on March 23, 2021Comments
-
Admin about 3 years
I have a bare repo server-side, and I am able to successfully commit and push from my local machine. However, the post-receive hook is not running. Details:
- Using SSH as protocol
- I have renamed the standard "post-receive.sample" to "post-receive"
- This file has
-rwxr-xr-x
permissions - The file is owned by the same user that owns the repo, which is the same SSH user that logs in and pushes
- The actual pushing goes fine; files are updated - it's just the hook that does not run
- I tried putting
echo "Some text"
before and after the hook, but this is not shown (see: Post Commit Hook Not Running). - Hook script is included below, although this appears not to be causing the problem
- Using git 1.7.0.4 on Ubuntu 10.04
.
user@server:/home/repos/project1/hooks# cat post-receive #!/bin/sh echo "Hook is running..." export GIT_WORK_TREE=/home/web/project1/www/ git checkout -f rm -rf /home/web/project1/www/temp/
-
halfdan over 12 yearsThat should be a comment, not an answer.
-
Andrew Kolesnikov over 12 yearsWrong. It is an answer. Hook is running, he just cant see it.
-
Admin over 12 years@AndrewKolesnikov Hook does not run, I tried putting
echo "test" > /home/web/project1/
and it does not create any file. Hook does work when trying it out locally. -
Andrew Kolesnikov over 12 yearsYour hook must be in user@server:/home/repos/project1/.git/hooks
-
Tim Post over 12 yearsThis is a proper answer. The question this answer begins with is quite obviously rhetorical.
-
Vineesh TP almost 5 yearscould not found post-receive file in '.git/hooks/'
-
trainoasis over 4 yearsHave the same issue but do not want even empty commits to clutter my branches. No other option?
-
Rakesh over 4 yearsI faced this issue when I was testing repeatedly in order to tweak my code deployment. Once the setup is completed, in the the real world, there will anyway be changes in the code base. so this issue wouldn't concern most of us. Having said that, the answer your question is, I have not investigated this further. so i don't know at the moment.
-
Kiee over 4 yearsAn alternative to this if your situation allows, is to delete the remote branch and re-push.
-
Bjarke over 4 yearsjust spent about an hour trying to debug this... your answer turned out to be correct 🤦♂️ thank you
-
Chris over 3 yearsTo answer the follow-up question, you can force an update without modifying the stack by setting the remote repo to an earlier commit ie- git commit -f branch repo:commit_id ..I'm dealing with this right now and that's the best way I've found to do it.