# Automated Deployment via Git and GitHub on Hosting & VDS

https://bihostnet.com/en/knowledgebase/article/git-github-automated-deployment-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

1. Connect to your VDS via SSH: `ssh root@server_ip`
2. Verify Git is installed: `git --version`
3. Navigate to web directory: `cd /home/user/public_html`
4. 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.php` script that triggers `shell_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**.
