GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com โ€” GitHub - BaseMax/github-actions-ssh-git-pull: A plug-and-play GitHub Actions template for automated CI/CD deployments over SSH. On every push to your repository, it connects to your remote server, performs a git pull, and optionally restarts your service (via systemctl, pm2, etc.). Perfect for personal projects, VPS-hosted apps, or lightweight Docker updates - no extra tools required.

BranchesTags
Open more actions menu

Latest commit

 

History

13 Commits
13 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 

Repository files navigation

GitHub Actions SSH Git Update Template

This repository provides a GitHub Actions CI/CD template to automatically update code from Git and restart a Linux service or PM2-managed app on a remote server using SSH.

๐Ÿš€ Ideal for deploying updates to remote Git projects directly from your GitHub repository.


โœจ Features

  • โœ… Automatic deployment on push to main (or any branch)
  • ๐Ÿ” Secure connection via SSH (using GitHub secrets)
  • ๐ŸŒ€ Pulls the latest code from Git
  • ๐Ÿ” Restarts a Linux service or PM2 process
  • ๐Ÿ”ง Easy to fork and adapt for any project

๐Ÿ“‚ Project Structure

.github/
โ””โ”€โ”€ workflows/
   โ””โ”€โ”€ deploy.yml # CI/CD workflow

โš™๏ธ Prerequisites

  1. Remote server with:
    • Git installed
    • PM2 (for Node.js apps) or a systemd-managed service
    • SSH access configured
  2. GitHub repository with:
    • This template copied or forked
    • Required secrets added (see below)

๐Ÿ” Required GitHub Secrets

Go to your repo โ†’ Settings โ†’ Secrets and variables โ†’ Actions โ†’ New repository secret and add:

Secret Name Description
SSH_HOST IP or domain of your remote server
SSH_USERNAME SSH user with access to the project directory
SSH_KEY Private SSH key (no passphrase)
SSH_PASSWORD SSH password with access to the project directory
PROJECT_DIRECTORY Absolute path of the Git project on the server
RESTART_COMMAND Command to restart the service or PM2 app

๐Ÿ“ฆ GitHub Actions Workflow - SSH by Key (.github/workflows/deploy-git-ssh-key.yml)

name: Deploy via SSH by Key

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repo
        uses: actions/checkout@v4

      - name: Set up SSH
        uses: webfactory/[email protected]
        with:
          ssh-private-key: ${{ secrets.SSH_KEY }}

      - name: Connect and Deploy
        run: |
          ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} << 'EOF'
            cd ${{ secrets.PROJECT_DIRECTORY }}
            git fetch origin main
            git reset --hard origin/main
            git clean -fd
            if [ -n "${{ secrets.RESTART_COMMAND }}" ]; then
              eval "${{ secrets.RESTART_COMMAND }}"
            fi
          EOF

๐Ÿ“ฆ GitHub Actions Workflow - SSH by Password (.github/workflows/git-ssh-password.yml)

name: Deploy via SSH by Password

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Install sshpass
        run: sudo apt-get update && sudo apt-get install -y sshpass

      - name: Deploy to Server via SSH
        env:
          SSHPASS: ${{ secrets.SSH_PASSWORD }}
        run: |
          sshpass -e ssh -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} << EOF
            cd ${{ secrets.PROJECT_DIRECTORY }}
            git fetch origin main
            git reset --hard origin/main
            git clean -fd
            if [ -n "${{ secrets.RESTART_COMMAND }}" ]; then
              eval "${{ secrets.RESTART_COMMAND }}"
            fi
          EOF

๐Ÿš€ Quick Start

  • Fork this repo (or copy deploy.yml to your own)
  • Add the required GitHub secrets
  • Ensure SSH access from GitHub to your remote server
  • Push to main branch - the deployment runs automatically!

๐Ÿ› ๏ธ Customization

Change main to another branch in the on.push.branches section

Use different RESTART_COMMAND values such as:

  • pm2 restart app-name
  • sudo systemctl restart my-service
  • npm run build && pm2 reload ecosystem.config.js

๐Ÿงช Testing

You can manually trigger a run from GitHub:

Go to Actions โ†’ Deploy via SSH โ†’ Run workflow

๐Ÿงพ License

MIT License - feel free to use and adapt.

๐Ÿ™‹โ€โ™‚๏ธ Author

Max Base (Ali)

๐Ÿ”— GitHub: @BaseMax

About

A plug-and-play GitHub Actions template for automated CI/CD deployments over SSH. On every push to your repository, it connects to your remote server, performs a git pull, and optionally restarts your service (via systemctl, pm2, etc.). Perfect for personal projects, VPS-hosted apps, or lightweight Docker updates - no extra tools required.

Topics

cdcici-cdcicddeploygitgithub-actiongithub-actionsgithub-actions-cigithubactionlinux-servicepm2servicesshsystem-servicesystemctl

Resources

Readme
MIT license
Activity

Stars

2 stars

Watchers

0 watching

Forks

1 fork
Report repository

Releases

Packages

Used by

Contributors

You are visitor 01402503 โ€” GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800ร—600. No cookies required.