How to Enable and use Git


Git is installed by default on all of our hosting accounts (cPanel/WHM)
Note:
You must have SSH Access enabled. Click here for our guide on enabling SSH, and click here for our guide on connecting to SSH.

Configuring your cPanel account for Git

  1. Log in via SSH.
  2. Initialise a git repository in the directory where the site is meant to reside e.g. public_html

    While inside the directory type git init then press Enter.
  3. Configure the repository to accept pushes directly into this working directory

    Type git config receive.denyCurrentBranch ignore then press Enter.
  4. Configure a git hook which will refresh the working directory after the push has been accepted. This hook will be a very simple shell script.

    While in the git directory type nano .git/hooks/post-receive then press Enter

    Paste or Type the following text into the editor:

    #!/bin/sh
    GIT_WORK_TREE=../ git checkout -f

    Then press “Control – X” on your keyboard

    Then press “y” on your keyboard

    Then press “Enter” to save the file

    Now type chmod +x .git/hooks/post-receive and then press Enter to make the file executable.
  5. You will now need to configure the remote repository by running the following commands:

    git remote add YOUR_REPOSITORY_NAME CPANEL_USERNAME@YOURDOMAIN.NET.AU:PATH_TO_GIT_DIRECTORY

    For example - git remote add myawesomesite username@website.com:public_html
  6. You should now be able to push changes from your remote repository to your live site

    git push myawesomesite master


Did you find this article useful?