How to use Git Version Control in cPanel
Help centreOn this page
This guide shows how to keep a website’s code in Git on your hosting, pull changes from GitHub, GitLab or similar, and copy the code into your live folder with a deploy file.
Before you start
Git Version Control works best for sites you build yourself, such as static sites, custom PHP or apps. For WordPress, it’s usually only worth tracking your own theme or plugin, not the whole install.
Don’t create the repository directly in public_html. The .git folder would sit in your web root. Keep the repository outside it, for example in /home/cpuser/repositories/mysite, and deploy the files across.
Clone an existing repository
- Log in to cPanel.
- In the Files section, open Git Version Control.
- Click Create.
- Leave Clone a Repository switched on.
- In Clone URL, paste the repository address. For a public repository the
https://address works. For a private one, use the SSH address, which looks likegit@github.com:yourname/mysite.git(see below). - In Repository Path, type a folder such as
repositories/mysite. - In Repository Name, type a label you’ll recognise.
- Click Create.
cPanel copies the repository to the server. This can take a minute for large projects.
Create a new, empty repository
- Open Git Version Control and click Create.
- Switch Clone a Repository off.
- Fill in Repository Path and Repository Name.
- Click Create.
cPanel shows a clone URL for the new repository. You can clone that to your computer over SSH, commit work locally and push it back.
Deploy with a .cpanel.yml file
Deployment copies files from the repository into your live folder. cPanel does this by running the commands in a file called .cpanel.yml at the top level of the repository. Add it to your project and commit it.
A simple example that copies everything into public_html:
---
deployment:
tasks:
- export DEPLOYPATH=/home/cpuser/public_html/
- /bin/cp -R * $DEPLOYPATH
Replace cpuser with your cPanel username. You can list specific folders instead of * if you only want part of the project live. Note that * skips hidden files, so copy files like .htaccess by name if you need them.
To deploy:
- In Git Version Control, click Manage next to the repository.
- Open the Pull or Deploy tab.
- Click Deploy HEAD Commit.
The Last Deployment Information box shows when it last ran. Deployment only works when the repository has no uncommitted changes on the server and a valid .cpanel.yml exists.
If you push to the repository on our server directly, cPanel can deploy automatically each time you push.
Pull changes from a remote
If your code lives on GitHub or GitLab and you push there, you need to fetch the changes on the server.
- Click Manage next to the repository.
- Open Pull or Deploy.
- Click Update from Remote.
- Then click Deploy HEAD Commit to put the changes live.
On the Basic Information tab you can switch Checked-Out Branch if you deploy from something other than main.
SSH keys for private repositories
GitHub and GitLab need to know the server is allowed to read a private repository. The usual way is a deploy key.
- In cPanel, open SSH Access in the Security section and click Manage SSH Keys.
- Click Generate a New Key. Leave the passphrase empty, as Git in cPanel can’t type one for you, and click Generate Key.
- Back on Manage SSH Keys, click View/Download next to the public key (the one ending
.pub) and copy its contents. - In your GitHub repository, go to Settings, then Deploy keys, and add the key with read access. GitLab has a similar Deploy keys page.
- Return to Git Version Control and clone using the SSH address.
The first connection may need the host added to your known hosts file. If the clone fails with a host key message, connect over SSH once and run ssh -T git@github.com, then answer yes. See how to connect to your hosting with SSH.
If it doesn’t work
- Clone fails with “Permission denied (publickey)”. The deploy key isn’t added to the repository, or you used the
https://address for a private repository. - The Deploy button is greyed out. There’s no
.cpanel.ymlin the top folder, or the working copy on the server has uncommitted changes. - Deploy runs but nothing changes. Check the path in
DEPLOYPATHand that it ends with a slash. - Files appear but the site errors. Look in the error log. See how to find error logs in cPanel.
Still stuck? Open a support ticket and we’ll help.
Every plan has cPanel, free SSL, backups every six hours and free migration.