DEV Community

SWAPNIL AHMMED SHISHIR
SWAPNIL AHMMED SHISHIR

Posted on

๐Ÿš€ How to Deploy GitHub Repositories to cPanel | Git Version Control + SSH Key Setup Step-by-Step Guide ๐Ÿ”ฅ

Deploying code from a GitHub repository directly to your cPanel hosting server is an efficient and secure way to manage your web projects. In this article, you'll learn how to deploy GitHub code to cPanel using Git version control and SSH key authentication, step by step.

โœ… Why Use Git with cPanel?

  • ๐Ÿ’ก Easy project version management
  • ๐Ÿ”„ Fast updates with one command
  • ๐Ÿ” Secure, key-based deployment (no password required)
  • ๐Ÿšซ No need for manual uploads via FTP

๐Ÿงฉ Prerequisites

Before we begin, make sure you have the following:

  • A GitHub account and repository ready
  • Access to cPanel with SSH enabled (Namecheap, Hostinger, etc.)
  • Your local machine with Git installed
  • Basic understanding of SSH and terminal commands

๐Ÿ›  Step-by-Step Setup Guide

๐Ÿ”น Step 1: Enable SSH Access in cPanel

  1. Log into cPanel
  2. Search for and open โ€œSSH Accessโ€
  3. Click on โ€œManage SSH Keysโ€
  4. Generate a new SSH key or import your existing public key:
  • If generating: set a passphrase (recommended), and click Generate
    1. Under โ€œPublic Keysโ€, click โ€œManageโ€ โ†’ Authorize

โœ… This ensures your server will recognize SSH connections from your local machine.

๐Ÿ”น Step 2: Copy Your Public SSH Key to GitHub

  1. In cPanel, under SSH Access โ†’ Manage SSH Keys, click View/Download on your public key (id_rsa.pub)
  2. Copy the entire key contents
  3. Go to your GitHub profile โ†’ Settings โ†’ SSH and GPG keys
  4. Click โ€œNew SSH keyโ€
  • Title: cPanel Server
  • Paste the key
  • Click Add SSH Key

๐Ÿ”น Step 3: Log In to cPanel via SSH (Optional Test)

From your local terminal, run:

โœ… Example:

ssh your_cpanel_username@yourdomain.com -p your_port
Enter fullscreen mode Exit fullscreen mode

Use the same port shown in your cPanel's SSH Access section (often 21098 on Namecheap).

๐Ÿ”น Step 4: Create or Choose a Deployment Folder

Example: a subdomain like api.content.com points to:

/home/yourcpanelusername/api.content.com
Enter fullscreen mode Exit fullscreen mode

You can deploy into:

  • public_html/ for your main site
  • Or any subdomain directory

๐Ÿ”น Step 5: Prepare the Folder for Git

cd ~/api.content.com
Enter fullscreen mode Exit fullscreen mode

If the folder already contains files, back them up:

mkdir _backup
mv * .[^.]* _backup 2>/dev/null
Enter fullscreen mode Exit fullscreen mode

This ensures the folder is clean for Git.

๐Ÿ”น Step 6: Clone Your GitHub Repository

Now clone your repository directly:

git clone git@github.com:yourusername/your-repo.git .
Enter fullscreen mode Exit fullscreen mode

The . clones the repo into the current folder.

If successful, your files are now deployed into your live cPanel server.

๐Ÿ”น Step 7: Set Up Git Remote for Future Pulls (Optional)

You can update the remote origin like this:

git remote set-url origin git@github.com:yourusername/your-repo.git
Enter fullscreen mode Exit fullscreen mode

And later, pull new changes:

git pull origin main
Enter fullscreen mode Exit fullscreen mode

Replace main with your actual GitHub branch if different.

๐Ÿ” Optional: Use cPanel Git Version Control GUI

cPanel also includes a Git GUI:

  1. Go to โ€œGit Version Controlโ€ in cPanel
  2. Click Create
  3. Paste your GitHub repo URL
  4. Choose deployment path (e.g., public_html/project)
  5. Click Create

โœ… This allows you to deploy code with a click from the cPanel dashboard.

โš ๏ธ Tips & Warnings

Tip Description
git pull doesn't work? Make sure the folder is a valid Git repo (git status)
Permission denied? Your SSH key may not be authorized or added to GitHub
Avoid FTP Itโ€™s slow, unsecure, and outdated
Backup before deploying Use _backup or git stash to avoid overwriting live files

๐ŸŽฏ Conclusion

With this setup, you now have:

โœ… SSH access to your server
โœ… Git version control linked to GitHub
โœ… Ability to deploy code into any subdomain or folder easily

Whether you're managing a simple portfolio or a full API backend, this Git + SSH workflow on cPanel will save you time, effort, and stress.

๐Ÿง  Have Questions?

Drop a comment below or reach out if you need help with:

  • Auto deployment scripts
  • GitHub Actions + cPanel
  • Laravel/Next.js app deployment to cPanel

๐Ÿ”ฅ Stay productive, stay version-controlled!

Top comments (0)