Git pre-deploy hooks to avoid deploying with local changes

Published on 2021-01-05 • Modified on 2021-01-05

In this snippet, we will see how to prevent deploying when you have local changes, and you didn't push all your work to your deploy branch. It is something it happened to me in the past when I go too fast. I run my tests; all is OK locally then I deploy. Except that I have forgotten to commit a file or to push (Yes, I should have waited for the CI build to pass!). So I have added these two Git commands to my Makefile to avoid this. The first one checks if there are modified or added files, and the second one checks if there is something to push on my main branch.


## —— Deploy & Prod 🚀 —————————————————————————————————————————————————————————
deploy: ## Full no-downtime deployment with EasyDeploy (with pre-deploy Git hooks)
	@test -z "`git status --porcelain`"                 # Prevent deploy if there are modified or added files
	@test -z "`git diff --stat --cached origin/master`" # Prevent deploy if there is something to push on master
	@$(SYMFONY) deploy -v                               # Deploy with EasyDeploy

 More on Stackoverflow   Read the doc  Random snippet

  Work with me!