Shared Hosting Git Deployment

HostGator has been my registrar of choice since I first registered my first domain; however, I have also register a few domains with GoDaddy and (far fewer) with Initially, my needs were simple: give me an easy WordPress or Joomla install and I was happy than a pig in slop. Times, however, have changed. With the exception (somewhat ironically) of this site, I no longer work on WordPress or Joomla sites and instead tend to do more direct web development or ship sites on Rails or some other web development framework. This shift in development platform and time / experience have of course brought a number of other changes with them. For one I am now a big proponent of continuous deployment in the web development space; I’ve been deploying new versions of Fingertip Tech, INC’s website every day since this new redesign.

Unfortunately, the site is hosted on a shared hosting account rather than a ‘real server,’ so I was relatively sure that I was doomed to FTPing my changes up to the host each time  I made a change; in my defence, I was developing a small Ruby script that would FTP changes up based on Git commits. As luck would have it, that wasn’t necessary.

As luck would have it HostGator rocks and I was able to get SSH access to my hosting account with a simple phone call and for no additional charge; I’ve dealt with some other hosting providers that covet SSH access and treat it as an add-on.

From there, all you have to do is SSH into your hosting account you will be greeted with something that looks a lot like the a UNIX file system. Once in the file system, you are going to want to put your public SSH key into the remote .ssh directory; if that directory does not currently exist, simply create one.

Now navigate to the www directory for the site you are trying to add Git deployment to. Run the following command ‘git config receive.denyCurrentBranch ignore’. Then navigate to .git/hooks/post-recieve and add ‘GIT_WORK_TREE = ../ git checkout -f’.

On your local repo you will need to add a new remote pointing to your shared hosting directory and you may need to change the SSH port to 2222. Hope this helps someone.

Comments are closed.