How do I force git
to run a post-receive
hook on a server even if I don\'t have a new commit to push?
I use git to aut
I'm afraid you have to ssh to the server and run the hook script manually. git push
doesn't make the server run the pre-push, pre-receive and post-receive hooks if there was nothing added (i.e. when git prints Everything up-to-date).
The rest of the answer is about version-tracking the post-receive hook, so you can modify it without sshing to the server.
Add a shell script named do-post-receive
to the local repository:
$ ls -ld .git
$ echo 'echo "Hello, World!"' >do-post-receive
$ git add do-post-receive
$ git commit do-post-receive -m 'added do-post-receive'
Replace your hooks/post-receive
hook on the server with:
#! /bin/sh
while read OLDID NEWID BRANCH; do
test "$BRANCH" = refs/heads/master && eval "$(git show master:do-post-receive)"
done
(Make sure to chmod 755 hooks/post-receive
on the server.)
Push your changes from the local repository to the server, and watch your do-post-receive
code run:
$ git push origin master
...
remote: Hello, World!
...