cPanel natively supports Gitweb a web frontend to Git repositories.

And our cPanel customers can host Git™ repositories on their cPanel server as long as the appropriate permissions are present and granted.

While many of the Git tasks will require command-line access, the Gitweb interface allows you to browse your repositories, view file contents, review log, commit, and other information from within this simple interface.

It also allows you to view historical information for your repositories in Gitweb.

How to Host Git Repositories on a cPanel Account

This tutorial can create or clone a new Git repository, update the repository's configuration, and clone the repository locally for updates.

However before you can use this feature, these statements must be true without exception:

  • Your cPanel account must be active with enough available disk space.
  • Shell Access setting must be enabled for your cPanel account.
  • You must have generated and registered your public key in cPanel's SSH Access interface (cPanel >> Home >> Security >> SSH Access) and authorize it for SSH access.
  • A stable Internet connection. Disconnect from VPN if you are using one. I often noticed that the best time to do this during early morning hours when internet connection speed is super-fast.

In this tutorial, "example_repo" represents the repository name and "Project" represents the directory that contains the repository.

Creating A Repository:

While it always better to create a new, empty directory for your repository (makes it easier to troubleshoot issues), you can also create a Git repository for any existing directory that you have.

If a Git repository already exists for your project, you can just clone it to your cPanel account instead.

It is worthy to note that cPanel’s Git Version Control interface at cPanel >> Home >> Files >> Git Version Control enforces several restrictions on repository paths:

For example, you cannot include whitespace or the following characters in repository paths:

\\ \* | " ' < > & @ \` $ { } [ ] ( ) ; ? : = % #

You also cannot use this feature with repositories in the following cPanel-controlled directories:

.cpanel .trash etc mail ssl tmp logs .cphorde spamassassin .htpasswds var cgi-bin .ssh perl5 access-logs

If you using the command line to create a repository in a restricted path, the interface likely will not display the repository.

To manage an existing repository in cPanel’s Git Version Control interface (cPanel >> Home >> Files >> Git Version Control), create a repository in that repository’s directory.

The system will automatically update the repository’s configuration and add it to the list of cPanel-managed repositories.

To create a new repository:

  1. Log in to your cPanel account via shell access.
  2. cd to the directory that will contain your repository with the following command: cd ~/Project/example_repo

    If you wish to create a new directory to store your repository, navigate to that directory:

    mkdir -p ~/Project/example_repo
  3. Navigate to the newly-created directory with the following command:
    cd ~/Project/example_repo
  4. Initialize the directory as a Git repository: git init

How To Clone An Existing Repository To Your cPanel Account:

  1. SSH into your cPanel account.
  2. Navigate to the newly-created directory: cd ~/Project
  3. If you want to create a new directory to store your repository, then:
    mkdir -p ~/Project
  4. To clone the repository, run the following command where URL represents the full Git URL of the existing repository to clone: git clone https://domain\name.com/Account/example_repo.git example_repo.git

    Until this process finishes, HEAD information will be unavailable in cPanel's Git Version Control interface (cPanel >> Home >> Files >> Git Version Control).

This process may take time as the system requires a large amount of time to clone larger repositories.

How To Update The Repository's Git Configuration:

You can configure the Git repository to remain up to date as you push changes from the local branch.

To do that, run the following command from within the repository directory:

git config receive.denyCurrentBranch updateInstead

How To Clone The Repository Locally:

To add and manage SSH keys that you can use to access the cPanel-hosted repository, scroll down to the cPanel's SSH Access interface at cPanel >> Home >> Security >> SSH Access.

But note that the SSH keys allow access to the entire cPanel account;  not just a single repository.

So exercise the utmost caution when you are doing this.

Consider using SSH config files to enforce the use of a particular SSH key for a particular repository.

In order to do so, we’ll need to set up an SSH config file per SSH key that we want to use:

# ~/.ssh/config-github-client-one
Host github.com
    HostName github.com
    Port 22
    User git
    IdentityFile ~/.ssh/id_rsa_client_one

And a second config file for the other client, that references a different SSH key:

# ~/.ssh/config-github-client-two
Host github.com
    HostName github.com
    Port 22
    User git
    IdentityFile ~/.ssh/id_rsa_client_two

You now have two SSH config files that each use a different SSH key for the same SSH connection.

The only thing we need to do is to tell Git to use either of the two files for our repository.

See Github Managing Deploy Keys at https://developer.github.com/v3/guides/managing-deploy-keys/

 

To clone the cPanel-account-hosted repository, run the following command:

git clone ssh://username@hostname/home/username/Project/example_repo.git

where:

  • username represents the cPanel account username.
  • and hostname represents the hostname of the server that hosts your cPanel account.

How To Push Local Changes To The Hosted Repository:

To push changes to the hosted repository after making changes to the repository’s files on your local system, first:

git push origin master -u

This will push your revisions to the copy of the repository that exists on your cPanel account.

If you have a valid account and run into an issue, please see other documentation on Git or contact our technical support team for assistance.

Was this answer helpful? 0 Users Found This Useful (0 Votes)