Need help deploying code via Git? Contact our support team and we'll assist you.


cPanel's Git Version Control tool lets you create bare Git repositories on your hosting account and deploy code directly from GitHub, GitLab, or Bitbucket. This guide covers how to set up a repository and deploy your code.

What You Can Do With Git in cPanel

  • Clone a remote repository (e.g. from GitHub) to your hosting account.
  • Automatically deploy code when you push to a branch.
  • Maintain version-controlled deployments without FTP.

Step 1: Access Git Version Control

  1. Log in to cPanel (my.hostdada.co.uk/cpanel).
  2. Go to Files > Git Version Control.
  3. Click Create.

Step 2: Create a Repository

Option A: Clone a Remote Repository

  1. Toggle Clone a Repository to on.
  2. In Clone URL, enter your repository URL — e.g.:
    https://github.com/yourusername/yourrepo.git
    or for SSH:
    git@github.com:yourusername/yourrepo.git
  3. Set the Repository Path — this is where the files will be deployed on your server. For example:
    /home/yourusername/public_html
  4. Give the repository a name (any label you like).
  5. Click Create.

Option B: Create a New Bare Repository

  1. Leave Clone a Repository off.
  2. Set the repository path and name.
  3. Click Create.
  4. Use the repository URL shown to push to it from your local machine.

Step 3: Set Up SSH Key Authentication (Recommended for Private Repos)

For private repositories, use SSH key authentication rather than HTTPS with a password:

  1. In cPanel, go to Security > SSH Access.
  2. Click Generate a New Key and follow the prompts.
  3. View the public key and copy it.
  4. Add the public key to your GitHub/GitLab account under Settings > SSH and GPG Keys.
  5. When cloning, use the SSH clone URL format: git@github.com:yourusername/yourrepo.git

Step 4: Deploy Your Repository

  1. In cPanel's Git Version Control page, find your repository and click Manage.
  2. Under the Pull or Deploy tab, click Update from Remote to pull the latest changes from your remote repository.
  3. To deploy the working tree to the repository path, click Deploy HEAD Commit.

Automating Deployment with a .cpanel.yml File

You can automate what happens after each deployment by adding a .cpanel.yml file to the root of your repository:

---
deployment:
  tasks:
    - export DEPLOYPATH=/home/yourusername/public_html/
    - /bin/cp -r . $DEPLOYPATH

When you push to the repository, cPanel runs the tasks defined here. This lets you copy files to your web root, run scripts, clear caches, and more.


Pushing to cPanel From Your Local Machine

If you created a bare repository in cPanel rather than cloning from GitHub, push to it like this:

# Add cPanel repo as a remote
git remote add cpanel ssh://yourusername@yourdomain.com/home/yourusername/reponame.git

# Push your branch
git push cpanel main

Troubleshooting

  • Clone fails (authentication error): For private repos, use SSH keys rather than HTTPS — GitHub deprecated password authentication for HTTPS.
  • Files not appearing in public_html: Ensure your .cpanel.yml deployment task copies files to the correct path, or use Deploy HEAD Commit manually.
  • Permission denied on push: Verify your SSH public key is correctly added to both cPanel (SSH Access) and your Git provider.
  • Repository path conflict: If public_html is already a Git repository (e.g. from a previous clone), you'll need to remove it first or use a subdirectory.

If you need help connecting your Git repository or setting up automated deployments, open a support ticket and our team will help you get it working.

آیا این پاسخ به شما کمک کرد؟ 0 کاربر این را مفید یافتند (0 نظرات)