How to Use Git Version Control in cPanel

cPanel's Git Version Control tool lets you keep your website's code in a Git repository on your Instant Access Internet Services hosting account, pull changes from GitHub, GitLab or Bitbucket, and deploy them to your live site. This guide covers how to use Git version control in cPanel: cloning a repository, updating it, and setting up deployment with a .cpanel.yml file.

Before you start

  • Git Version Control is for people who already use Git. If you just want to upload a few files, File Manager or FTP is simpler.
  • Keep the repository outside public_html (for example /home/username/repositories/mysite) and deploy only the files your site needs. That way the .git folder, with your full code history, is never visible on the web.
  • If your site is WordPress, WP Toolkit (Domains > WordPress Management) is usually a better way to manage it. Git is best for custom sites, themes or plugins you develop yourself.

How to clone a Git repository in cPanel

  1. Log in to cPanel and go to Files > Git Version Control.
  2. Click Create in the top-right corner.
  3. Leave the Clone a Repository toggle turned on and paste your repository's address into Clone URL, for example https://github.com/yourname/mysite.git. The URL must start with https://, http://, ssh:// or git:// (or use the git@github.com:yourname/mysite.git style), and it must not contain a username or password.
  4. In Repository Path, enter where the files should go, for example repositories/mysite. cPanel fills this in for you based on the repository name.
  5. In Repository Name, enter a label you'll recognize. This only appears in cPanel.
  6. Click Create. cPanel clones the repository and adds it to your list.

To start a brand-new, empty repository instead, turn the Clone a Repository toggle off, fill in the path and name, and click Create. You can then push to it from your computer using the clone URL cPanel shows on the repository's Manage page.

Some folders can't hold a repository, including mail, etc, ssl, tmp, logs, .ssh, cgi-bin and access-logs.

How to pull updates from GitHub or GitLab

  1. In Files > Git Version Control, click Manage next to the repository.
  2. On the Basic Information tab, check the Checked-Out Branch is the one you want (usually main).
  3. Open the Pull or Deploy tab and click Update from Remote.

cPanel pulls using fast-forward only. If you edited files directly in the cPanel copy, the pull can fail; make changes in your own copy and push them to the remote instead.

How to deploy your site with .cpanel.yml

Deployment copies files from the repository to your live website. It runs the commands listed in a file named .cpanel.yml in the top level of your repository. Add this file to your repository on your own computer and push it to GitHub or GitLab. Here is an example that copies a few files and a folder into public_html:

---
deployment:
  tasks:
    - export DEPLOYPATH=/home/username/public_html/
    - /bin/cp index.html $DEPLOYPATH
    - /bin/cp style.css $DEPLOYPATH
    - /bin/cp -R images $DEPLOYPATH

Replace username with your cPanel username (shown in the General Information panel on the cPanel home page). Avoid wildcards like *: they can copy the .git folder onto your website.

To deploy:

  1. Click Manage next to the repository and open the Pull or Deploy tab.
  2. Click Update from Remote to fetch the latest commits.
  3. Click Deploy HEAD Commit. The Last Deployment Information area shows when it ran.

Deployment needs a valid .cpanel.yml file and a clean working tree (no uncommitted changes in the cPanel copy). If you push directly to the cPanel-hosted repository from your computer, deployment runs automatically on each push.

How to clone a private repository

A private repository needs an SSH key so the server can prove it's allowed to read it. This requires shell access (SSH or Terminal).

  1. In cPanel, go to Advanced > Terminal (or connect with SSH) and create a key with no passphrase:
    ssh-keygen -t rsa -b 4096 -f ~/.ssh/repo -C "you@example.com"
  2. Show the public key with cat ~/.ssh/repo.pub and copy the whole line.
  3. On GitHub, open the repository's Settings > Deploy keys > Add deploy key and paste it. (GitLab and Bitbucket have similar "deploy key" or "access key" settings.)
  4. Create the file ~/.ssh/config containing the lines below, then run chmod 600 ~/.ssh/config:
    Host github.com
        IdentityFile ~/.ssh/repo
  5. Test with ssh -T git@github.com and answer yes to accept the host's fingerprint.
  6. Back in Git Version Control, clone using the SSH address, for example git@github.com:yourname/mysite.git.

Common questions

How do I see the commit history?

Click History next to the repository. It opens Gitweb in a new tab, where you can browse commits, branches and files.

Deploy HEAD Commit is greyed out

The repository either has no .cpanel.yml file in its top level or has uncommitted changes. Check the file is committed and pushed, then click Update from Remote again.

Does removing a repository from cPanel delete the files?

No. Removing it from the list only stops cPanel managing it; the files stay on disk until you delete them in File Manager.

Clone fails with "Permission denied (publickey)"

The repository is private and the server's key isn't set up or authorized. Follow the private repository steps above and make sure the deploy key was saved on GitHub.

Related guides

Still stuck? Open a support ticket and the Instant Access Internet Services team will help.

Ultrafast LiteSpeed hosting from InstantAccess.net: free SSL, free backups, cPanel included, no contracts. Check out our $10/month hosting.
  • cpanel git version control, cpanel git deployment, cpanel.yml example, clone github repo cpanel, deploy website with git, cpanel private repository ssh key
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to Change Your PHP Version in cPanel

Running a current PHP version keeps your website faster and more secure, and many WordPress...

How to Change PHP Settings (memory_limit, upload_max_filesize)

If WordPress says "The uploaded file exceeds the upload_max_filesize directive", a plugin runs...

How to Set Up a Cron Job in cPanel

A cron job runs a command or script on a schedule, such as every hour or once a night, without...

How to Check Your Website Error Log and Recent Visitors

When your website shows a blank page, a "500 Internal Server Error" or a feature just stops...

How to View Website Statistics with AWStats and Bandwidth

Your Instant Access Internet Services hosting account includes built-in website statistics, so...