Here are the simple steps needed to create a deployment from your local GIT repository to a server based on this in-depth tutorial.
Connect to Digitl Ocean Droplet using SSH or VS Codem once in create the deploy folder and ensure you have the below structure:
/var/www/placeholder.com/repo
/var/www/placeholder.com/temp
/var/www/placeholder.com/html
Now we create a "bare" repository – one that does not contain the working copy files. It basicaly is the content of the .git repository folder in a normal working copy:
$ cd repo && git init --bare .
This scrtipt is executed when the push from the local machine has been completed and moves the files into place. It recides in repo/hooks/ and is named 'post-receive'. You can use vim to edit and create it. The script does check if the correct branch is pushed (not deploying a develop branch for example). You can download a sample post-receive script below. Also, don't forget to add execute permissions to said script (SUPER IMPORTANT)
cd hooks
chmod +x post-receive
Now we add the this bare repository to your local system as a remote. Where "live" is the name you want to give the remote. This can also be called "staging" or "production" or "test" etc if you want to deploy to a different system or multiple systems.
$ git remote add live [email protected]:/var/www/placeholder.com/repo
Now you can push the branch to the live server:
$ git push live {branch_name}
- https://macarthur.me/posts/deploying-code-with-a-git-hook
- https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
- https://www.digitalocean.com/community/tutorials/how-to-set-up-automatic-deployment-with-git-with-a-vps#local-machine
- https://kags.me.ke/post/digitalocean-setup-git-server-deploy-with-hooks-ubuntu/
- https://www.youtube.com/watch?v=k3BYVduyjyI