Thanks for posting this question, automatic deployment is a complex task I will try to describe it here.
First you need to have a git repository to host your code, there are many available applications that allow you to host your code for example: github and gitlab.
After you setup a git repository you need a continuous integration tool to automatically run builds when you push new code to the repository, gitlab has its own CI tool known as gitlab CI and it is very easy to use, you can also use jenkins or (travis)[https://travis-ci.org] with github.
Now last you need a code deployment tool to deploy new code each time you push it to the repository, you can use (ansible)[https://www.ansible.com] or (capistrano)[https://capistranorb.com].
I hope this helps you if you need further questions please do not hesitate to ask.