How to deal with Git on our shared servers

1. Overview

Git is a distributed version control system. While it may sound confusing, it helps to address a number of important and topical problems, such as: 

  • having multiple versions of one file or a group of files edited by a group of people with an ability to save all versions - from early ones to latter ones
  • avoiding of important files overwriting
  • tracking revision history (each change is prompted to be documented)

With Git, it’s not necessary to manually back up file copies before saving them. 

For example, having a group of files in your production folder with different names but similar functions, such as: 
  • .htaccess
  • .htaccess_backup
  • .htaccess.bp
  • .htaccess_mary
  • .htaccess_secured
  • .htaccess2015-06-12 
will only end in a disaster. 

With implementing git version control system, all of your changes will be under control. Originally, it was created to manage the Linux kernel source code, and nowadays, it is in active use by many developers globally. 

2. Git installation

Git is pre-installed on our shared servers. The absolute path to the executable file is as follows: 


You may need to install it on your local computer as well. Our recommendation is to use following pieces of software: 
using such commands as: 
  • sudo yum install git for Fedora and CentOS
  • sudo apt-get install git on Debian-based systems, such as Ubuntu.  

3. Creating a local repository and committing

The most usual workaround for using Git involves having a number of local remote repositories (on developers’ computers) and one remote repository used to share code between a group of developers and move things to production at some point later. 

With a local git repository a developer may track his/her own changes and prepare to committing to a shared remote repository a concise piece of code. 

In order to create a local Git repository, create a directory first (using the mkdir shell command, for example). Then, change the directory to the newly created one ( the cd command may come in handy) and use the git init command: 

EAC Directory; Git

Next, you’ll need to find files you want to be controlled to the version control index. The command to do that is: 

git add <file> such as: 
git add example.php 

Multiple files should be separated with spaces: 

git add example.php sample.txt readme

If you want to add all of the files in the directory, you may use a shortcut: 

git add . ( with ‘.’ at the end): 

EAC Directory; Git

In order to commit the file change to a local repository, the following command is to be used: 

git commit -m “commit comment”, like this: 
git commit -m “test commit” 

EAC Directory; Git

4. Working with the remote repository hosted at a Namecheap shared server

Our recommendation is to manage a remote Git repository over SSH. It provides a considerable level of security, convenience and integration. You may request SSH access granted for your shared hosting account with the help of our Support Team. 

First of all, specify your path to be extended to with the /usr/local/cpanel/3rdparty/bin directory where Git executables are located so that it wouldn’t be necessary to type the full path each time Git is addressed. 

To do that, type the following command into your SSH command prompt while connected to the your hosting account over SSH: 

nano .bashrc

A GNU Nano text editor screen will appear. Append its contents with the following lines: 

export PATH 

EAC Directory; Git

After that, press CTRL+X , then press and Enter to save changes. In order for the changes to be accepted it will be necessary to re-log into your SSH command prompt. 

Now, you may create a repository the same way it was done locally. Once done, we are ready to get local changes pushed to the remote repository. 

You may create an alias for a remote repository on your local device for your convenience: 

git remote add origin ssh://<username>@<servername>:21098/home/<username>/public_html/<directory_of_site>

  • <username>  should be replaced with your cPanel username;
  • <servername>  should be replaced with your server hostname
  • /public_html/<directory_of_site>  should be replaced with the path to your remote repository

EAC Directory; Git

After that, you may push changes to the remote repository with the help of the following command, while in the local git repo directory: 

git push -u origin master 

EAC Directory; Git

or its full alternative if no aliases/shortcuts were used: 

git push --receive-pack=/usr/local/cpanel/3rdparty/bin/git-receive-pack ssh://<username>@<servername>:21098/home/<username>/public_html/<directory_of_site> master 

That's it!
  • 422 Users Found This Useful
Was this answer helpful?

Related Articles

 How to force www or non-www in your .htaccess file in cPanel

1. Log into your cPanel.  2. Find the Files category and click on the File Manager icon.3. Click...

 Restricting IP addresses access to subdomain via .htaccess file

In cPanel-> under Subdomains section you can create the subdomain for your domain.   After...