3

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?

Biggie Mac
  • 1,307
  • 2
  • 13
  • 26
  • 1
    pos-receive hook will work if you put it into gihub repo if possible. Then it will execute when you do `git push`. – Foolish Aug 18 '15 at 04:46

2 Answers2

1

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.

Foolish
  • 3,952
  • 33
  • 46
0

In short, post-commit is a client-side hook, whereas post-receive is a server-side hook, and must be installed in the remote repository that you are pushing to.

To elaborate, git will look for client-side hooks only in your local git repository's .git/hooks directory and will run these only for this one local repo. Similarly, git will look for server-side hooks only in your remote repository's hooks directory and will run these whenever any repo tries to push to it. You can read more about which is which in the git hooks docs

The "fix" is to mv your post-receive hook into the hooks directory of your remote (origin) repository, which can be retrieved via git remote -v

Note that if you are using GitHub or the like, access to installing hooks is not allowed for security reasons, e.g. see here, and you will need to resort to WebHooks or the like.

Community
  • 1
  • 1
lemonhead
  • 5,328
  • 1
  • 13
  • 25