I would like to add multiple post-receive hook scripts to a git repository on my own server. For example: triggering CI, and posting to slack.

How can I add more than one script?


You can only have one post-receive script, so you'll have to use that one to call multiple scripts.

On the server in the /PATH/TO/GIT.git/hooks/post-receive file, put the following:

while read oldrev newrev refname; do
    for hook in $GIT_DIR/hooks/post-receive.d/*; do
        echo -e "\e[44m\e[97m Running hook: $hook \e[0m"
        echo $oldrev $newrev $refname | $hook

exit 0

Then put all your post-receive scripts inside a new post-receive.d/ directory. Make sure the script files are executable.

└── post-receive.d
    └── SCRIPT1
    └── SCRIPT2

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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