Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git post-receive hook not working but post-commit works

Tags:

git

Long story short, I created a test repo on github, cloned it locally on my linux machine. Created a post-commit hook with the following content:

#!/bin/bash
echo Test message

Added perms 777 for the hook, changed a file and when I performed the commit, I got the message on the console. So the post-commit hook seems to work. I now renamed the hook from post-commit to post-receive but after push I get no message. I keep committing and pushing to master and no message is displayed. The hook is just the same, has 777, has same content so I can't understand why as post-commit the hook works but as post-receive it doesn't. Am I missing something obvious?

like image 347
Biggie Mac Avatar asked Jan 27 '26 17:01

Biggie Mac


1 Answers

Suppose you have two repos

  1. local (in your case cloned from github in your machine)
  2. Origin (repo on github)

post-commit works as below

You put post-commit in your local repo and it will execute everytime after you commit in this local repo. So this works in your case.

pos-receive works as below

This hook is meant to be run after the commits are received. So if you put this in your local repo this won't work. This hook needs to be on the origin repo. And whenever you push to this origin, after receiving your commits this hoook will execute on origin. In short, post-receive will work on repo that is receiving commits from other repo. (In this case the repo on github). Hope this helped.

like image 158
Foolish Avatar answered Jan 30 '26 20:01

Foolish



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!