These instructions are an adaption of these articles for my particular needs I hope this could help somebody else's:
The first thing to do is to install Git on the cPanel server.
sudo yum install git-core
Once you do that the rest of the process is split into three sections:
- Server set-up
- Local set-up (push commits)
- Server (pull commits)
Note: First of all you need to have SSH access to your cPanel account.
ssh [email protected]
(this is you connecting to your remote server)
Note: Your web directory is public_html
then move up one level from there.
The remote repository you’re going to push to will be a separate directory than the actual you're deploying. Locally, the repository is always the code directory, but for remote deployments, we need to do things a bit differently.
mkdir repos && cd repos
mkdir your-project.git && cd your-project.git
git --bare init
We’ve now created a bare repository on our web server that we will use as our remote location.
The next step is to setup our post-receive hook. This is a script that will run every time you push code to the remote repository.
vi hooks/post-receive
Now, put this code into your post-receive file (replacing the path with the full path to where you want the code deployed).
#!/bin/sh
GIT_WORK_TREE=/home/username/public_html git checkout -f
After that’s done, you’ll need to give the post-receive file execute rights so it’ll actually do the work:
chmod +x hooks/post-receive
cd ~/Sites/myWebsite
git init
git add *
git commit -m 'Start of new project'
git remote add origin ssh://[email protected]:xxxx/~/repos/your-project.git
git push origin master