Complete guide to Git Version Control in cPanel

Complete guide to Git Version Control in cPanel

On cPanel Git can be used in two ways:

  1. clone a remote repository (e.g. from GitHub) to cPanel
  2. create a repository on cPanel and use it in a remote location (e.g. your pc)

Here I will cover both ways and highlight some important steps that are not mentioned in cPanel docs. Before we start, here are some terms that I will be using in this guide:

gitan open-source, distributed version control system
clonecreate a local copy of some repository
remotea common repository on another site, e.g. GitHub
gitweban interface that allows browsing a git repository using a web browser

Create a Git Repository in cPanel

Q: Why would you create a Git repository in cPanel?

A: You can create a git repo from your WordPress files on cPanel, then edit them locally on your PC. When you’re finished, simply submit changes back to cpanel. This gives you a free staging copy of your website to work on locally.

How to create a Git Repository in cPanel

Step 1. From cPanel go to Files > Git

image 54 - Complete guide to Git Version Control in cPanel

Step 2. Click on Create button

image 55 1024x517 - Complete guide to Git Version Control in cPanel

Step 3. By default, cPanel toggles the git clone option, but because We want to create a new repository We will toggle off the Clone a Repository button.

image 58 - Complete guide to Git Version Control in cPanel

Step 4. Fill in the file path to the new repository. In this example, I will use the public_html folder where I have a WP site installed.

image 57 - Complete guide to Git Version Control in cPanel

Step 5. Provide a name for the repository as it will appear in your cPanel interface, e.g. wp-site.

image 59 - Complete guide to Git Version Control in cPanel

Step 6. Click on the Create button.

image 60 - Complete guide to Git Version Control in cPanel

cPanel will create the repository and provide you with some helpful Git commands that you can use.

image 61 1024x517 - Complete guide to Git Version Control in cPanel

In this screen cPanel states commands for two cases:

  1. For an existing project
  2. To start a new project

But, if you like me already have files in the directory (WordPress files) and now want to download those files to your computer using git clone, you first have to run the following commands in cPanel terminal:

1. enter the repository

cd /home/domain/public_html

2. Set your email address

git config --global user.email "you@example.com"

3. Set your Name (will be shown in git history)

git config --global user.name "Your Name"

4. Aldo you have physical files in the git repository (public_html folder), git still doesn’t know that these files exist and if you now clone the repository on your PC you will get an error: “You appear to have cloned an empty repository.

To include all files from this folder to Git, run the following command:

git add .; git commit

This will open a screen that will ask you to set a commitment message and show you all files that are going to be included in git:

image 62 - Complete guide to Git Version Control in cPanel

5. Type the commit message, for example, initial commit, and then type :quit + enter to exit Vim editor.

Now all files have been added to Git and you can clone/pull the repo to your local computer.

git clone ssh://user@example.com:22/home/domain/public_html

NOTE: If your hosting provider has disabled password logins for SSH and only allows access with SSH keys, then you first need to register an SSH key first.


Clone a Git Repository in cPanel

Aside from creating a new repository, you can also clone another git repo from sites like giuthub.com

Q: Why would you clone a Git repository from GitHub to cPanel?

A: This is a quick way to test some repositories, for example, you could test my JS terminal in less than a minute.

How to Clone a Git Repository in cPanel

Step 1. From cPanel go to Files > Git

image 54 - Complete guide to Git Version Control in cPanel

Step 2. Click on Create button

image 55 1024x517 - Complete guide to Git Version Control in cPanel

Step 3. Copy the URL into the Clone URL field

In this example I will use: https://github.com/stefanpejcic/terminal

image 63 - Complete guide to Git Version Control in cPanel

Step 4. cPanel will suggest a path, but you can alter it if you want.

image 64 - Complete guide to Git Version Control in cPanel

Step 5. Provide a name for the repository as it will appear in your cPanel interface, e.g. terminal.

image 65 - Complete guide to Git Version Control in cPanel

Step 6. Click Create button

This image has an empty alt attribute; its file name is image-60.png

You will be redirected back to the Git™ Version Control page and after cloning is done you will see the newly cloned repository:

image 66 1024x517 - Complete guide to Git Version Control in cPanel

TIP: Gitweb, a Git web interface is available in cPanel. It allows browsing a git repository using a web browser.

To lunch Gitweb for your repository, simply click on History button next to it.

image 67 - Complete guide to Git Version Control in cPanel

You will be redirected to another page where you can browse the repository

image 68 1024x517 - Complete guide to Git Version Control in cPanel

For more useful Git commands check my Git CheatSheet – a practical git tutorial for beginners, focusing on the commands that are used daily by every programmer.

whoami
Stefan Pejcic
Join the discussion

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.