Git deployment on cPanel hosting: clone a GitHub repository and publish it with .cpanel.yml
PrintIn short: cPanel can keep a copy of your GitHub project and push its files to the live site whenever you ask. The tool is called Git Version Control and sits among the Files tools. A small .cpanel.yml file tells it what to copy, and SSH access to the hosting is not required.
Many developers keep their code on GitHub and still upload changes by hand through FTP or File Manager. That works, but it is slow and easy to get wrong. With Git in cPanel, the code on GitHub becomes the single source, and an update of the site takes two clicks.
Before you start
- Your project is already on GitHub. If the repository is private, first set up a read-only key as described in Private GitHub repository on cPanel hosting: setting up a read-only deploy key (ed25519).
- You know your cPanel username, since the deployment path contains it.
- The site files are grouped in one folder of the repository (we use
publicbelow), not mixed with notes, tests or configuration.
How the process works
cPanel never clones straight into the website. It keeps the project in a separate folder of your account, for example repositories/site. When you deploy, it reads .cpanel.yml from that copy and runs the commands written there. Those commands put the chosen files into public_html. So there are two places: the repository copy, which only Git touches, and the site folder, which visitors see.
Prepare .cpanel.yml
Create this file at the top level of the repository, commit it and push it to GitHub:
---
deployment:
tasks:
- export DEPLOYPATH=/home/USERNAME/public_html/
- /bin/cp -a public/. $DEPLOYPATH
Put your own cPanel username in place of USERNAME. If your site lives in a folder with another name, change public to that name. Indent the lines with spaces only; a tab breaks the file. Keeping the site in its own folder also means that .git, .cpanel.yml and any private notes stay out of public_html.
Add the repository to cPanel
- Sign in to cPanel and find Git Version Control under Files. Not in your panel? Send us a ticket and we will look at your account.
- Press Create, keep Clone a Repository switched on and paste the GitHub address into Clone URL, for example
https://github.com/username/site.git. - Set Repository Path to an empty folder outside the site, such as
repositories/site, type any Repository Name and press Create.
A small project of a few MB is copied in seconds.
Put changes live
Each time you have pushed new work to GitHub:
- Go back to Git Version Control, press Manage on your repository and switch to the Pull or Deploy tab.
- Press Update from Remote. cPanel fetches the newest commits from GitHub.
- Press Deploy HEAD Commit. The commands from
.cpanel.ymlrun and the site gets the new files.
Nothing happens on its own between these clicks. If you prefer the site to follow every push automatically, see How to deploy a website from GitHub automatically: GitHub Actions with FTPS on hosting or rsync on a VPS.
Pick the method that fits your project
| Your project | Recommended way |
|---|---|
| Open-source or public repository | Clone over HTTPS, exactly as in this guide |
| Private repository | A GitHub deploy key with read-only rights, then the same steps |
| You want hands-free updates on each push | A GitHub Actions workflow that uploads over FTPS |
| The site needs an npm build step (React, Vue, Astro) | Run the build in GitHub Actions or locally and upload only the output |
Troubleshooting a failed deploy
| What you see | What to check |
|---|---|
| The deploy button does nothing or the files never arrive | Is .cpanel.yml at the top level of the repository? Is it indented with spaces rather than tabs? |
| cPanel refuses to deploy | Someone edited files inside repositories/site. Only a clean copy can be deployed, so make edits on GitHub or on your computer. |
| Files land in the wrong place or nowhere | Look at DEPLOYPATH: the username must match your account and the folder must exist. |
Good to know
- SSH is optional. All three actions (clone, update, deploy) run from the cPanel interface. A shell only helps if you like using Git commands.
- Old files stay. The
cpcommand adds and replaces files but never removes them. Clean up leftovers in File Manager. - Keep
public_htmlout of it. cPanel needs an empty target folder, and a clone there would expose the.gitfolder to visitors. - No secrets on GitHub. Database passwords and API keys must not be committed, even to a private repository. Protecting API keys in cPanel apps and WordPress: safe storage and leak response shows where to keep them.
Useful articles
- Private GitHub repository on cPanel hosting: setting up a read-only deploy key (ed25519)
- How to deploy a website from GitHub automatically: GitHub Actions with FTPS on hosting or rsync on a VPS
- SSH access on cPanel hosting: enabling it, Terminal and SSH clients
- Where to upload website files in cPanel: public_html and domain folders