How to Connect Git with cPanel for Public and Private Repositories

Muhammad Abdullah
Software Engineer & Tech Enthusiast

The First Time I Used Git with cPanel

I still remember manually uploading zip files through cPanel’s File Manager every time I made a change to my Laravel project. It was slow, repetitive, and stressful. Then I discovered cPanel’s built-in Git Version Control feature. With a few steps, I could connect my GitHub repo directly and deploy changes instantly. If you are still dragging and dropping files, this chapter is for you.

Why Use Git with cPanel

Integrating Git with cPanel saves you time and reduces errors. Instead of manually uploading files, you just push to your repo, and cPanel pulls the changes for you. This means:

Connecting a Public Repository

Public repos are the easiest to connect since they don’t require authentication.

  1. Log into your cPanel dashboard.
  2. Go to Files > Git Version Control.
  3. Click Create.
  4. Enter the public GitHub repo URL, for example: https://github.com/username/project.git.
  5. Choose the deployment directory, e.g., /home/username/public_html/project.
  6. Click Create. cPanel will clone the repo automatically.

From now on, you can pull updates directly in cPanel or set up automatic deployment.

Connecting a Private Repository

Private repos need authentication. Here are two common methods:

1. Using SSH Keys

  1. In cPanel, open the SSH Access section and generate a new SSH key pair.
  2. Add the public key to your GitHub account under Settings > SSH and GPG keys.
  3. Back in cPanel, authorize the key and ensure it is active.
  4. Now go to Git Version Control and create a repo with the SSH URL, e.g., git@github.com:username/private-repo.git.

2. Using Personal Access Token (HTTPS)

  1. Create a Personal Access Token in GitHub under Settings > Developer settings > Personal access tokens.
  2. Copy the HTTPS repo link: https://github.com/username/private-repo.git.
  3. When cPanel asks for credentials, use your GitHub username and the token instead of your password.

Deploying Changes

Once the repo is connected, deployment is easy:

# SSH into your cPanel account and go to the repo directory
cd ~/public_html/project

# Pull the latest changes
git pull origin main

Or use the cPanel Git interface to deploy updates with one click.

Benefits of Using Git with cPanel

Pro Tips From Experience

Mistakes to Avoid

  1. Pushing secrets: Never commit .env or sensitive files, even in private repos.
  2. Skipping SSH setup: For private repos, SSH keys save you endless headaches.
  3. Mixing code and uploads: Keep deployment directories clean, avoid pushing large media files into Git.

The Reality Check

cPanel’s Git integration is a game-changer for developers on shared hosting. It bridges the gap between local development and live deployment, saving time and reducing errors. Public repos connect easily, private repos require some setup, but both unlock a smoother, more professional workflow. Once you set it up, you will never want to go back to uploading zip files again.

Think of it as bringing modern Git workflows to traditional hosting. It makes you faster, safer, and more confident every time you deploy.