How to deal with Git on our shared servers
1. Overview
2. Git installation
3. Creating a local repository and committing
4. Working with remote repository, hosted at Dream Line IT Solution shared server
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 backup 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 disaster.
With implementing git version control system, all of your changes will be under control. Originally, it was created to manage 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 is as follows:
/usr/local/cpanel/3rdparty/bin/git
You may need to install it to your local computer as well. Our recommendation is to use following pieces of software:
Tortoise git – for Windows;
Atlassian Sourcetree – for Mac and Vanilla Git for Linux system – using commands such as:
sudo yum install git – for Fedora and CentOS and sudo apt-get install git on Debian-based systems, such as Ubuntu.
You can be find more details here
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 on 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 mkdir shell command, for example). Then, change the directory to the newly created one (cd command may come in handy) and use git init command.
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)
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”
4. Working with remote repository, hosted at Dream Line IT Solution 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 in your SSH command prompt, while connected to the your hosting account over SSH:
nano .bashrc
A GNU Nano text editor screen will appear. Append it’s contents with the following lines:
PATH=$PATH:/usr/local/cpanel/3rdparty/bin
export PATH
After that press CTRL+X , then press Y and Enter to save changes. In order for changes to be accepted it will be necessary to re-log in to 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>
where:
– <username> should be replaced with your cPanel username;
– <servername> should be replaced with your server hostname (click here to find out how to check a server hostname);
– /public_html/<directory_of_site> should be replaced with the path to your remote repository.
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
or it’s 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
This is it!
Need any help? Contact us via Helpdesk




