Search code examples
gitdeploymentgit-push

How to deploy website using Git?


I want to use Git to deploy my local Laravel website to my server. I have been reading tutorials on how to do this, but they all mention writing some post-receive web-hook, which me being very new to Git, don't fully understand.

Could someone explain to me, why using git push to my public_html is not enough? I tried it but it did not copy any of my website files so I am guessing I am missing something here (probably web-hooks). Why does not git push copy everything from my local directory on to my server?

Thanks!

EDIT:

I have been following this tutorial:

https://blog.sebduggan.com/2012/03/13/deploy-your-website-changes-using-git/

Why do we need a web-hook for the server to checkout the repo we push our changes to into my web root? Why cant we just submit our changes directly to the web root?


Solution

  • git hooks are just some executable doing anything you wrote in a bash script. What you probably missing is to add a hook to move to the version you just pushed. This simply is a bash script which will call git checkout -f to update that directory. More information here

    UPDATE

    If you just don't want to use hooks, you can achieve this another way. You can create a center repository like gitlab or github then push your changes there. Then clone that project in your server and instead of pushing changes to server you should pull changes from server.