Using GIT to deploy to Live sites

Niall Deakin
10 Aug 19

A little secret

Okay, today I’m going to tell you a nice little method I’ve been wanting to try out for ages.

If you are unaware of CI/CD, Jenkins, Auto Deployment, DeployHQ, etc., they’re essentially methods to push changes to a site with as little interruption as possible.

Instead of manually uploading via FTP yourself, what these services do is use a number of methods to update your live site to avoid down-time.
This way it’s between the two servers, and not my computer, which I am using and can have uploading issues.

This doesn’t stop programmer errors, but checks that the files don’t break the site (and makes sure all get uploaded).

What are the options

There are a number of options, as mentioned previously. I’ve had the most success with DeployHQ, but that is a paid-for service.
GitLab has a nice little feature built-in, but I’ve not been able to (con)figure it out*.

* see, that’s a joke because you need to configure the settings

So, after scratching my head for a while, I had an idea. I understand Git pretty well, so why not just pull from the repo to the Live site?

Well, I’ve just tried it now, and it works!

Method

Okay, so I had my site live for quite a while now, but I need to use the Git repo. The easiest way was to make a copy of my site’s directory and give it another name as a backup.

Then, once I was happy, I cloned the repo to the server. For this instance, I cloned it into a different name (because safety), but you could just clone it directly down if it’s a fresh site (or you are feeling daring).

Once cloned, all the files will be on the site and good to go (or renamed to the correct name if you are being cautious like me).

Now whenever I make changes to my site, I can test locally, see they work and push up as normal.
I then log into my server and simply fetch and changes and pull them down for the site.

The process is no different than if you are working on two different machines and need to keep the code up to date.

Final thoughts

I’m pretty sure there are quite a few redundancies in place using other, more fleshed out, processes, but as I keep a close eye on what is going on and know what should happen, this suffices (for now).

Using a similar “cautious” method, I could clone into a separate directory, make sure it has worked correctly, then rename the folder (deleting the old/current).

But hey, this is just a shot in the dark to try and make my life a bit easier.

After all, it’s better to expend more energy to automate a process than have to do it manually all the time.

CI/CD, DeployHQ, Deployment, FTP, Git, Gitlab, Jenkins, SSH, Uploading