Automated Deployment via Git and GitHub on Hosting & VDS
Why Use Git & GitHub for Web Deployment?
Deploying via Git eliminates manual and error-prone FTP transfers. With Git, updates can be synchronized to production environments in seconds using atomic commits.
Cloning a Repository via SSH
- Connect to your VDS via SSH:
ssh root@server_ip - Verify Git is installed:
git --version - Navigate to web directory:
cd /home/user/public_html - Clone repository:
git clone https://github.com/user/repo.git .
Automated Deployment with GitHub Webhooks
To auto-pull changes on every push to the main branch:
- Place a secured
deploy.phpscript that triggersshell_exec('git pull origin main'); - In GitHub, go to Settings > Webhooks > Add Webhook.
- Set Payload URL to your webhook endpoint and trigger on Push events.
Was this helpful?
Thanks for your feedback!