Guide to Git™ — Host Git Repositories on a cPanel Account
Last modified: November 13, 2024
Overview
We recommend that you use cPanel’s Git Version Control interface (cPanel » Home » Files » Git Version Control) to perform Git tasks. While many of these tasks require command-line access, this interface automates some parts of the process and allows you to view historical information for your repositories in Gitweb.
With the appropriate permissions, cPanel accounts can host Git repositories. Git’s version control software tracks changes in a system of files that multiple users can manage simultaneously. This tutorial uses the command line to create or clone a new Git repository, update the repository’s configuration, and clone the repository locally for updates.
-
For a list of common Git commands and their options, read our Common Git Commands documentation.
-
For information about how to deploy code from your hosted Git repositories, read our Deployment and Set Up Deployment Cron Jobs documentation.
-
For more information about Git, read Git’s documentation.
Requirements
To perform the steps in this tutorial, you must meet the following requirements:
- You must possess an active cPanel account with available disk space.
- Your system administrator must enable the Shell Access setting for your cPanel account.
- You must register your public key in cPanel’s SSH Access interface (cPanel » Home » Security » SSH Access) and authorize it for SSH access.
To clone private repositories, you must perform the additional steps in our Set Up Access to Private Repositories documentation.
Host a Git repository on your cPanel account
Create or clone a repository
You can create a Git repository in any existing directory, or you can create a new, empty directory for your repository. If your project already has a Git repository, you can clone the repository to your cPanel account instead.
To use cPanel’s Git Version Control interface (cPanel » Home » Files » Git Version Control) to manage your repository, you must ensure the repository and directory you place it into meet the following requirements:
-
You cannot include whitespace or the following characters in the repository name or directory path:
\\ \* | " ' < > & @ \` $ { } [ ] ( ) ; ? : = % #
-
The repository cannot be in the following cPanel-controlled directories:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
.cpanel .trash etc mail ssl tmp logs .cphorde spamassassin .htpasswds var cgi-bin .ssh perl5 access-logs
If you use the command line to create a repository in a restricted path, the Git Version Control interface (cPanel » Home » Files » Git Version Control) will not display the repository.
Create a new repository
To create a new repository, perform the following steps:
-
Use SSH to log in to your cPanel account on the command line.
-
To navigate to the directory that will contain your repository, run the following command, where :
cd ~/Project/example
Note:To create a new directory to store your repository, run the following command and then navigate to that directory:
mkdir -p ~/Project/example
-
To initialize the directory as a Git repository, run the following command:
git init
Clone an existing repository
To clone private repositories, you must perform additional steps. For more information, read our Set Up Access to Private Repositories documentation.
To clone an existing repository, perform the following steps:
-
Use SSH to log in to your cPanel account on the command line.
-
To navigate to the directory that will contain your repository, run the following command:
cd ~/Project
Note:To create a new directory to store your repository, run the following command and then navigate to that directory:
mkdir -p ~/Project
-
To clone the repository, run the following command :
In this example,git clone https://domain.com/Account/example.git example.git
https://domain.com/Account/example.git
represents the repository’s clone URL.
- Many developers host their code repositories on GitHub. GitHub repository URLs generally resemble the following example, where
Account
represents the GitHub account name andexample
represents the repository name:
https://github.com/Account/example.git
-
The system may require a large amount of time to clone larger repositories. Until this process finishes, HEAD information will be unavailable in cPanel’s Git Version Control interface (cPanel » Home » Files » Git Version Control).
-
cPanel’s Git Version Control interface (cPanel » Home » Files » Git Version Control) does not allow username-and-password pairs in remote repository URLs.
Update the Git configuration
This optional step configures the Git repository to remain up to date as you push changes from the local branch.
For more information about Git’s configuration file and its options, read Git’s git-config documentation.
To update the configuration, run the following command from within the repository directory:
git config receive.denyCurrentBranch updateInstead
Clone the repository locally
- This feature enforces several restrictions on clone URLs. For more information, read our Git Version Control documentation.
- You can use cPanel’s SSH Access interface (cPanel » Home » Security » SSH Access) to add and manage SSH keys, which you can use to access the cPanel-hosted repository. Because SSH keys allow access to the entire cPanel account, and not just a single repository, exercise caution when you perform this action.
To clone the cPanel-account-hosted repository, access your local computer via the command line and run the following command:
git clone ssh://username@hostname/home/username/Project/example.git
-
username
represents the cPanel account username. -
hostname
represents the hostname for the server that hosts your cPanel account.
Push local changes to the hosted repository
After you finish this tutorial, you can make changes to the repository’s files on your local computer. You must run the following command in order to push changes that you make on your local computer to the hosted repository:
git push origin master -u
This command pushes your revisions to the copy of the repository that exists on your cPanel account.
cPanel & WHM’s Git installation will automatically configure some settings.