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:
- No more uploading zip files.
- Consistent deployments with fewer mistakes.
- Faster workflow between local, GitHub, and your live server.
Connecting a Public Repository
Public repos are the easiest to connect since they don’t require authentication.
- Log into your cPanel dashboard.
- Go to Files > Git Version Control.
- Click Create.
- Enter the public GitHub repo URL, for example:
https://github.com/username/project.git. - Choose the deployment directory, e.g.,
/home/username/public_html/project. - 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
- In cPanel, open the SSH Access section and generate a new SSH key pair.
- Add the public key to your GitHub account under Settings > SSH and GPG keys.
- Back in cPanel, authorize the key and ensure it is active.
- 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)
- Create a Personal Access Token in GitHub under Settings > Developer settings > Personal access tokens.
- Copy the HTTPS repo link:
https://github.com/username/private-repo.git. - 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
- Efficiency: Push once, deploy instantly.
- Security: SSH keys and tokens keep repos private and safe.
- Version Control: Roll back easily if something goes wrong.
- Professionalism: Brings real DevOps practices into shared hosting.
Pro Tips From Experience
- Keep your
.envfile outside Git and configure it manually on the server. - Ignore
/vendorand/node_modulesin Laravel projects, install them withcomposer installornpm installon the server. - Set up deployment hooks in cPanel if your hosting provider supports them, so changes are pulled automatically.
- Use separate repos or branches for development and production for safer deployments.
Mistakes to Avoid
- Pushing secrets: Never commit
.envor sensitive files, even in private repos. - Skipping SSH setup: For private repos, SSH keys save you endless headaches.
- 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.