How to Host Git Repositories with cPanel

You are here:
Estimated reading time: 3 min

Git is an open-source version control system(VCS) which tracks the history and versions of content (files and directories) and manages changes to a project without overwriting any part of the project. It allows developers to collaborate and work on a project at the same time.
The Git Version Control menu allows you to create or import Git repositories and host them in your cPanel account. The cPanel menu allows you to create, clone, view, and deploy repositories without having to log in to your account via SSH. The cPanel Git Version Control tool provides a convenient graphical interface that allows access to Git features without using the command line.

How to use Git Version control in cPanel to install and update a site

The steps below allow you to easily deploy and manage your projects.

  • To create an empty repository you will need to disable the Clone a Repository option.
  • Using your preferred text editor on your local machine, add a .cpanel.yml file to the root folder of your repository.
  • Add the following to .cpanel.yml
deployment: tasks: – export DEPLOYPATH=/home/cpanelUser/public_html/ – /bin/cp -R * $DEPLOYPATH

Replace the “cpanelUser” with your Cpanel username.
.Git Add, commit and push these changes to GitHub.

  • Head over to your cPanel account
  • Under files, select the Git Version Control tool
  • Toggle off the Clone a Repository button
  • Click Create, where you can start a new repository from scratch. This process will create the /.git folder in the newly created repository. Make sure you do not modify/delete the /.git directory or its contents. Any changes to this folder can break the repository irreversibly and lead to data loss.
  • In front of the newly created repository, click on “MANAGE”
  • Enter the file path to the new repository
  • Name the repository as it will appear in your cPanel interface
  • Click Create at the bottom
  • Then, it will be transferred to another screen with commands which you can use to push a Git repository from your PC to cPanel.
  • In the Repository Path text box, enter the path to the document root of the site, the document root is usually public_html. However, you can install the site in a public_html subdirectory if you wish.
  • Make sure to set the correct permissions on the directory so that the site is visible. In the Repository Name text box, enter a descriptive name for your repository.
  • Click Create.

Please note that Git Version Control will only show Git repositories created using the cPanel menu itself. Therefore, creating or deleting repositories via SSH will cause inaccuracy in the list of repositories displayed here.

Clone an Existing Repository into your cPanel Account

Be very careful when creating a repository in a directory that already contains files. If for some reason you delete the repository from cPanel, the entire directory will be deleted. Instead of creating your own Git repository, you can “clone” a repository that already exists on the web.

  • Head over to the cPanel
  • Under Files, Select Git Version Control
  • Copy the clone URL into the Clone URL
  • Enter the Repository path (remember the cloned repository provides its own directory)
  • Specify the repository name as it will appear in the cPanel interface
  • Click Create, and you will be redirected to your list of repositories and the cloning process will begin. This may take some time depending on the size of the repository, and all options for that repository will be disabled during the process, so you will not be able to manage or remove it until the clone is complete.

You have now successfully cloned a repository into your hosting account.

Managing an Existing Repository

The Manage option is divided into two tabs: Basic Information and Pull or Deploy. Both tabs share the following elements.
The repository path indicates the directory where the repository is located and allows you to open it in the file manager.
The remote URL is only available for repositories cloned from other sources and specifies the location of the source repository.
Currently, Checked-Out Branch displays the branches that have been checked out for this repository. It also allows you to access it in the Gitweb interface.
HEAD Commit displays information about the last commit (HEAD) in this Git repository.

In the Basic Information tab, you can also change the Repository name and select a different Checked-Out Branch. Any of these changes must be confirmed by clicking the Update button.

In the Pull or Deploy tab, you can also view information about the last deployment.. This is the information on the commit that is deployed at the moment, and the date of the deployment. There are also two buttons featured here:

Update from Remote, which is only available for cloned repositories and can be used to pull updates from the remote repository to the cPanel repository.

Deploy HEAD commit, which can be used to manually deploy the last commit.

To deploy a repository, you will need to go to the Manage Repository menu and press the Deploy HEAD Commit button in the Pull or Deploy tab.

Please note that cPanel automatically adds a post-receive hook to all new repositories which will trigger the deployment each time you push updates to the repository. Cloned repositories can only be deployed manually.

Why Create a Git Repository in cPanel

cPanel makes the process much easier by creating the repository and the necessary executable files to save and launch your project right away.

Was this article helpful?
Dislike 0

Author

Joshua

Web Hosting Geek Technical Support Staff G Online Sites