Use ‘–allow-empty’
After the initial push replacing the script, you can do this :
git commit --allow-empty -m 'push to execute post-receive'
The --allow-empty
flag overrides git’s default behavior of preventing you from making a commit when there are no changes.
Use an alias and make your life even easier
Add the following to ~/.gitconfig
[alias]
pushpr = "!f() { git push origin master;git commit --allow-empty -m 'push to execute post-receive';git push origin master; }; f"
Now Just do git pushpr
git pushpr
This will push any changes to master, which in your case will trigger your post receive replacement script, then it will push again (using the --allow-empty
flag) which will then execute your updated post-receive
script.