Set Up a Bitbucket Repository in cPanel (Git Version Control Integration)
Bitbucket is a git based source code management (SCM) platform built for team collaboration to make code development simple and easy. Learn how to set up a Bitbucket private repository in cPanel and get rid off of traditional file uploads via file manager clients.

A Git repository in cPanel provides a centralized source to keep code changes and makes it easier to pull the latest changes compared to manual file uploads. Another benefit it offers is that we can automate code deployment with a CI/CD service that automatically pushes the latest changes to the cPanel repository. This post explains how to clone a Git repository in cPanel in simple steps. Before we can begin with the integration, we need to make sure we have the following:
- Git Version Control support in cPanel.
- Terminal is enabled in cPanel. Required for creating SSH keys, etc.
How to Clone a Git Repository in cPanel?
The configuration requires a few simple but technical steps, such as creating a repository, SSH keys, and cloning it in cPanel using one of two methods. The following are the main steps for configuration:
- Create a Bitbucket repository.
- Create SSH Keys in cPanel.
- Assign SSH Keys to the Bitbucket repository.
- Clone the Bitbucket repository in cPanel.
Step 1: Create a Bitbucket Repository
- Log in to Bitbucket account.
- Navigate to the correct workspace. Click the user avatar icon at the top right to navigate to a different workspace, then click "All Workspaces".
- Click the "Create" button in the top menu, then click "Repository" in the dropdown.
- Select a project or create a new one.
- Enter a name for the repository.
- Check the "Access level" checkbox to make the repository private.
- Click "Create repository".

Step 2: Create SSH Keys in cPanel
Now that we have created our repository, we need to generate SSH keys before cloning the repository.
- Log in to the hosting server's client area and navigate to cPanel.
- Open "Terminal" and run this command to generate the SSH key:
ssh-keygen -t rsa -f ~/.ssh/bitbucket-cpanel -b 4096 -C "bitbucket-cpanel"
-t rsa: indicates the algorithm of the SSH key.
-f ~/.ssh/bitbucket-cpanel: indicates the name of the SSH key, including the path where the key will be stored.
-b 4096: indicates the size of the SSH key.
-C "bitbucket-cpanel" indicates a comment for the SSH key. Useful in case you have multiple keys for different repositories. This comment will help to identify the key.
After we have run this command, it will ask for a passphrase. Leave it empty and press Enter twice. - Run this command to create an SSH configuration file.
touch ~/.ssh/config
- Run this command to change the permissions of the SSH config file.
chmod 0600 ~/.ssh/config
- Run this command to change the owner of the SSH config file.
chown user:user ~/.ssh/config
Replace user in "user:user" with the cPanel username. - Now open ~/.ssh/config file in the file manager and add the following to the file.
Host bitbucket.org
AddKeysToAgent yes
Hostname bitbucket.org
IdentityFile ~/.ssh/bitbucket-cpanel
Step 3: Assign SSH Key to Bitbucket Repository
After generating SSH keys, we need to add them to our Bitbucket repository. So we go navigate to our repository in Bitbucket and follow these steps:
- Click "Repository Settings" in the left-side menu.
- Click "Access Keys" in the left-side menu.
- Click the "Add Key" button.
- Enter a nice descriptive label for the key.
- Copy and paste the contents of "~/.ssh/bitbucket-cpanel.pub" either by opening it in cPanel or running the "cat ~/.ssh/bitbucket-cpanel.pub" command. It will output the content of the key file in the terminal, which we can copy.
- Finally, click "Add SSH Key".

Step 4: Clone The Bitbucket Repository in cPanel
There are two different approaches to access private repositories that cPanel offers. The first one is to clone it via a Terminal command, and the other is using the Git Version Control tool.
4.1: Clone Repository via Terminal:
- Go to the repository home in Bitbucket.
- Clone the SSH URL of the repository from the clone modal.
- Head back to the cPanel terminal.
- Navigate to the directory where we want to clone this repository.
- Paste the clone command you copied from Bitbucket.
- Wait for cloning to complete, and that is it.

4.2: Clone Repository via Git Version Control:
I personally recommend this method to create/clone a repository via the Git Version Control Tool, as it will also create logs of commits and pulls.
- Go to Git Version Control under the "Files" section of your cPanel Tools.
- Click the "Create" button.
- Turn the option "Clone Repository" on if it is not on by default.
- Enter the clone URL of our repository in the URL field. The URL should be in this format "[email protected]:username/bitbucket-cpanel.git" where username is our Bitbucket username.
- Once the repository is detected, the "Repository Path" and "Repository Name" will be automatically filled. We can still change it as per our directory structure.
- Click "Create", and that is it.

We can now pull changes in the cPanel repository manually by accessing the Terminal, via SSH Agent from our local machine, or automatically deploy changes with CI/CD. Configuring a Git repository in cPanel provides many advantages over manual file uploads via FTP clients. It makes the deployment easier and faster, keeps the history of changes, offers better team collaboration, and makes it easy to roll back changes.