WordPress Git Workflow

By: Ryan Kienstra on: October 14, 2014  in: Programming

WPEngine has a full git system that lets you test on a staging server before deploying.

There won’t be any downtime, and you can test all changes on a full “mirror” site.

You can push code to the staging server in seconds. After testing it, deploying to production takes one click and a 30 second wait.

To see the workflow, skip to the “Push To Staging” section below.

Setup

Download WPEngine’s .gitignore file to your root WordPress directory. This won’t version any WordPress core files or wp-content/uploads/ files.

wget -O .gitignore http://cdn.wpengine.com/wp-content/uploads/2013/10/recommended-gitignore-no-wp.txt
git init # if not yet initialized

Though this allows most of your wp-content file to be under git control, I like to only keep the parent and child themes versioned. It’s easier to have wordpress.org host all of the plugins, and upload premium plugins in zip files.

git add wp-content/themes/example-theme
git add wp-content/themes/example-theme-child

WPEngine allows you to push to staging and production. But I think it’s best to only push to staging. You can test your site, and then click the button in your admin to copy from staging to live.

When you click this button, WPEngine makes a “checkpoint” backup of your entire production site. If you git push to production, you have to remember to create a backup point first.
Wpengine copy site buttons

Push To Staging

Create your staging site by going to your admin screen, clicking the “WP Engine” icon, clicking the “Staging” tab at the top, and clicking “Copy site from LIVE to STAGING.”

Then, make a commit if you need to, and push to staging.

git commit -am 'Pushing to staging site'
git push example-staging master

It only takes 5 to 10 seconds.
Git Push Image
After testing your site on the staging server, find the blue and black buttons again. Click “Copy site from STAGING to LIVE.” This won’t copy the database unless you want it to. So there won’t be any lost data if something happened on the production site while you were testing.
Wpengine copy site buttons

The deployment takes about 30 seconds, and you’ll get an email when it’s done.


Leave a comment