I've shared this script at a few conferences, used it on several servers, and it is still unmatched by most web host's git deployment methods.

The unique feature of this script is that it performs a two-way sync via git. Most services only handle deployment, pushing local changes to the server. Using an intermediary such as GitLab or Github, this script pushes changes from your desktop to the server, and changes on the server go to your desktop. That's important when you're using something like WordPress or Drupal and want to use the one-click updates.

Pros

  • This script is super lightweight. If you’re already running a PHP app, why would you want to install Ruby or something else just for deployments?
  • This script, unlike many others, is two-way. That means if you’re running WordPress you can still do you automatic updates right on the server, all while still having the warm sweet safety of a version to roll back to.

Cons

  • Setup can be a bit of a pain. You’ll need to set up a git user for your web server, along with proper permissions. If you’re not familiar with command-line git or linux permissions… well then you’re probably not looking for this script to begin with.
  • The only other con is that this script will blindly commit any changes on the server. That includes hacked code. This isn’t always a bad thing though. If you’re keeping an eye on your code, and you should, then you’ll notice when/if the server user makes unexpected commits. If you want, you can even set up alerts. You’ll have to roll back in the case of a hack, but you’ll also be able to very clearly see what code was manipulated. This can go a long way in sealing the hole after your recovery.

Here's a screenshot of what the end result looks like. Here you can see my usual theme alterations and a few plugin additions, and you can also see the automatic commits from the server. I use a picture of my adorable dog so the cuteness sticks out.

Tips

  • Be sure you use a properly configured gitignore file otherwise every cache folder update or file upload will trigger a commit.
  • Add a Cron job to run every so often just to make sure to grab any spontaneous changes on the server.
  • To really leverage this script, kill the use of FTP on your server. In the office we only allow access via Git. It makes managing permissions for projects super easy (just add developers to your repo), and ensures that there’s a record of every code change.

If you find any issues, or would like to contribute, please visit my GitLab page.