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?
Background
I use git to automatically deploy a website to a server. I have a bare repo in a protected area of the server and a post-receive
hook that checks out the contents and systematically copies over certain files into a public_html
folder. (Inspired by this tutorial)
I got tired of modifying the post-receive
hook manually on the server, so my post-receive
hook now actually copies over a new version of itself from the repo:
#!/bin/sh
rm -rf ~/../protected/*
GIT_WORK_TREE=~/../protected git checkout -f
# Rewrite over this file with any updates from the post-receive file
cp ~/../protected/post-receive hooks/post-receive
# Delete public_html
# Copy stuff public_html
The problem, of course, is that the new post-receive
hook never gets run. A seemingly simple solution would be merely to push again, but now everything is already up to date. This is annoying, because it requires me to fake a new commit every time I update the post-receive
hook. Is there a way to invoke the post-receive
hook without faking a commit or ssh
ing in?
What I tried
git push
git push -f