Skip to main content
⚡ OpenDevDocs
Deployment
devopsdeploymentGuideIntermediate

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.

Verified: 2026-09-30
Tested on:git 2.46.x
Platforms:
linuxcloud
#git#deployment#github-actions#webhooks#ci-cd

A Git-based deployment uses Git commits, tags, or branch pushes to trigger automated build, test, and release scripts on your destination production servers.


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 production

Method 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
```

On this page