The goal here is to be able to deploy the website update from a push.
For this we'll use hooks and a bare repo.
A bare repo is the git file without the working tree, i.e. the blueprint for all the code without the code itself.
This secific type of repo is used to be pushed to, it eliminate the risk of any problem that could come from pushing to a working tree
The hooks are script files that are called at certain point of git actions, you can put whatever you want in these files.
We are gonna use the
hook to deploy a working tree under the directory we want to be able to access through nginx (by default : /var/www/html).
Local Computer -push--> /var/www/git/ (bare) -deploy--> /var/www/html
The way I've done it is quite dirty, people usully create a git user, manage permission properly etc...
I don't really care cause that's my website but it may cause problems on larger team et setup.
# log in your server
# change ownership if needed with chown [user] [folder_name]
git init --bare
# add those two lines to the file
git --work-tree=/var/www/html --git-dir=/var/www/git checkout -f name_of_branch
# make it executable
chmod +x post-receive
# push from you local machine
git remote add origin ssh://your_user@server_ip_address:/var/www/git/