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!
...
I know this probably going to be considered "dangerous" but I like to live on the edge.
I just delete the remote branch and then push it again. Make sure your local branch is up-to-date first to limit the chance of losing stuff.
So if I want to trigger post-receive, in my case to get the testing branch to provision, all I do is:
$ git push origin :testing
$ git push origin testing
Don't accept this as the answer though. It's more of a just FYI thing.
In my case i login into remote and run:
$ sh project.git/hooks/post-receive
works fine!