Git in cPanel: clone and deploy a site

  1. Open "Git Version Control" (group "Files").
  2. Click "Create".
Repository list
Repository list
  1. Keep "Clone a Repository" on.
  2. "Clone URL" - the https address of the repository, for example https://github.com/user/my-site.git.
  3. "Repository Path" - the folder for the repository, for example repositories/my-site.
  4. "Repository Name" - a name for the list.
  5. Click "Create".
Cloning a repository
Cloning a repository

A public repository clones over https with no setup. For a private one, put an access token in the URL: https://TOKEN@github.com/user/repo.git (on GitHub - a Personal access token with read access).

A private repository is easier to connect with a passphrase-less SSH key - see Private GitHub repository: deploy key.

Deploying to the site folder

To copy files from the repository to the site folder, put a .cpanel.yml file in the repository root:

---
deployment:
  tasks:
    - export DEPLOYPATH=/home/USERNAME/public_html/
    - /bin/cp -R * $DEPLOYPATH

To update: "Manage" the repository - "Pull or Deploy" tab, buttons "Update from Remote" (fetch changes) and "Deploy HEAD Commit" (deploy).

Do not clone the repository straight into public_html if it contains files with passwords or a .git folder - they could be downloaded.

Questions and answers
Put an access token in the URL: https://TOKEN@github.com/user/repo.git.
In "Manage" for the repository - "Update from Remote", then "Deploy HEAD Commit". A .cpanel.yml file is required.