Basic Git-Based Deployments & CI/CD Webhooks
Complete guide to Git-based deployments, bare repository hooks (post-receive), GitHub Actions CD workflows, and automated deployment pipelines.
A Git-based deployment uses Git commits, tags, or branch pushes to trigger automated build, test, and release scripts on your destination production servers.
Method 1: GitHub Actions CI/CD (Recommended)
Create .github/workflows/deploy.yml to automatically deploy to your server via SSH when pushing to main:
name: Production Deployment
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Deploy to VPS via SSH
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.PROD_SERVER_HOST }}
username: appuser
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /var/www/api
git pull origin main
npm ci --omit=dev
npm run build
pm2 reload ecosystem.config.js --env productionMethod 2: Git post-receive Hook (Self-Hosted Git Push-to-Deploy)
Deploy directly to your Linux VPS by running git push production main:
```bash
#!/bin/bash
TARGET="/var/www/myapp"
GIT_DIR="/var/repo/myapp.git"
echo "====> Deploying new commit to $TARGET..."
git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f
cd $TARGET
npm ci --omit=dev
npm run build
sudo systemctl restart myapp
echo "====> Deployment successfully finished!"
```
Make the hook executable:
```bash
chmod +x /var/repo/myapp.git/hooks/post-receive
```Related Guides
Configuring Free SSL/TLS with Let's Encrypt & Certbot
Complete guide to obtaining, installing, and auto-renewing free SSL/TLS certificates for Nginx and Apache using Certbot and Let's Encrypt.
Nginx Master Guide & Web Server Architecture
Master Nginx from fundamentals to advanced production architecture — master/worker process model, asynchronous event-driven I/O, installation, and lifecycle management.