cPanel

Deploy a website with cPanel Git Version Control

Clone a GitHub or GitLab repository into cPanel with Git Version Control, pull updates, and deploy automatically to public_html with a .cpanel.yml file.

IntermediatecPanel hosting2 min read

Uploading files by FTP gets messy once a project has many changes. cPanel's Git Version Control clones your repository on the server, lets you pull new commits with one click, and can copy the right files into your website with a deployment file. You keep using GitHub, GitLab or Bitbucket as normal.

Before you start

  • A Git repository. For private repositories you need an SSH key that the Git host accepts (a deploy key).
  • Access to Terminal or SSH helps for creating the key.

Add a deploy key for private repositories

  1. Open cPanel → Advanced → Terminal and run:
    ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N ""
  2. Show the public key with cat ~/.ssh/id_ed25519.pub and copy it.
  3. In GitHub open the repository → Settings → Deploy keys → Add deploy key, paste it and save (read-only is enough).
  4. Back in Terminal, accept the host key once: ssh -T git@github.com and type yes.

Clone the repository

  1. Open cPanel → Files → Git Version Control and click Create.
  2. Leave Clone a Repository on.
  3. Clone URL: for private repos use the SSH form git@github.com:you/site.git; for public ones https://github.com/you/site.git works.
  4. Repository Path: a folder outside the web root, such as repositories/site. Keeping the repo out of public_html stops the .git folder from being downloadable.
  5. Repository Name: a label, e.g. site. Click Create.

Deploy with .cpanel.yml

Add a file named .cpanel.yml to the root of your repository. It lists shell commands cPanel runs when you deploy. Example for a static or PHP site:

---
deployment:
  tasks:
    - export DEPLOYPATH=/home/cpuser/public_html/
    - /bin/rsync -a --delete --exclude '.git' --exclude '.cpanel.yml' ./ $DEPLOYPATH

Replace cpuser with your cPanel username. Be careful with --delete: it removes files in public_html that are not in the repo, such as uploads. Exclude those folders, or drop --delete.

Pull and deploy updates

  1. Push your changes to the Git host as usual.
  2. In Git Version Control, click Manage next to the repository and open Pull or Deploy.
  3. Click Update from Remote to pull the latest commits.
  4. Click Deploy HEAD Commit to run the tasks in .cpanel.yml. The Last Deployment Information shows the result.

Tip: You can also push directly to the cPanel repository (its clone URL is shown in Manage). Pushing to cPanel triggers the deployment automatically.

Troubleshooting

  • "Permission denied (publickey)": the deploy key is missing on the Git host, or the key file is not in ~/.ssh/id_ed25519/id_rsa.
  • Deploy button greyed out: there is no valid .cpanel.yml in the repository root, or the working tree has uncommitted changes on the server.
  • Site shows old files: you pulled but did not deploy; or caching (LiteSpeed Cache) needs a purge.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.