Are you using Git in your development workflow only to stop short of using it in your code deployment because your host only offers FTP?
Well dry your eyes, because WP Engine has Git push integration for developers and it’s a beautiful thing. Now you can go through the entire development process AND deploy versioned code to your staging and production servers.
In the past I’ve used DeployBot for this (and I still love DeployBot), but since it’s now available as part of my WP Engine hosting plan, I decided to ditch the cost of DeployBot and switch over to Git push with WP Engine.
In this post I’ll walk you through how to set up and use Git push with WP Engine. At the end I also include a couple of “good to knows” about working with Git specifically on WP Engine. I might even share a WP Engine coupon code. 🙂
There are affiliate links in this post, but it’s only for services I’ve paid for and enjoy.
Add your SSH Public Key
Before you can start deploying your code to WP Engine, you need to do a little setup.
The first step is to add a SSH Public Key to the WordPress install where you want use Git push. This is how the WP Engine servers authenticate you and know when it’s you pushing code to their servers versus some stranger danger.
Navigate to the Git Push setup in the WPE User Portal
Log in to your account. From your WP Engine dashboard, select the install you want to set up for “git push.”
Get Your SSH Key
If you’re creating a new key, it’s pretty easy to copy/paste that right into your user portal. If you want to copy an existing key, here’s a handy command you can run from terminal to copy it to your clipboard:
pbcopy < ~/.ssh/id_rsa.pub
Note: That command assumes the name of the key you want to copy is id_rsa.pub. Adjust as necessary to match your file location and name.
Add Your Info
The last step is to paste your SSH key into the corresponding text area over on WP Engine (see screenshot above), add a unique developer name (this can be whatever you want), and click the Add Developer button.
Once you do this, WP Engine says it’ll take about 10 minutes before it’s ready for use. I’ve had it take longer than that, so don’t panic if it takes 30 minutes or even an hour.
Once it’s ready, you can run this from the command line to get a list of all repositories on WP Engine you can push to:
ssh firstname.lastname@example.org info
If you see your repository in the list, you’re ready. Note that you can give multiple developers push access to the repository, which is awesome if you’re working with a team.
The first time you connect to
git.wpengine.com (i.e. by running
ssh email@example.com info), you’ll need to confirm SSH host authenticity. This is a good thing. You’ll get a host fingerprint back and want to confirm that the fingerprint matches one of these host fingerprints for WP Engine’s Git Push feature:
ECDSA SHA256 Jgp8bPftGbM0rzQaeA7KTBrZa1UfEN1nqQMLIwu5i18
If it doesn’t match, don’t continue the connection. Here’s the documentation where I pulled those fingerprints.
Set up Git Remote
If you’ve used Git locally and ever pushed code up to a corresponding repository on Github, Bitbucket, or the like, then you’ve already worked with a remote repository and are familiar with the concept. That repository is often named “origin.”
To use WP Engine’s Git Push feature, we need to set up a remote repository on their server. This is pretty straightforward.
From the command land, navigate to the local repository you want to work with (this is the directory that contains your repository’s
Pro tip: If you’re on a Mac, here’s a really nifty setting to open a folder location in Terminal from a Finder window.
Every WP Engine install comes with a staging site and a production site. That means you can add remote repositories for both production and staging. Let’s add the location of our remote staging repository. We can do that with this command:
git remote add staging firstname.lastname@example.org:staging/my-repo.git
A couple of things to note about that command. The first instance of
staging is the “nickname” of the remote. You can call that whatever you want, like
git remote add boogers. This is the name you’ll use later when you’re pushing (or fetching) code. For example:
git push staging master
The second instance of
staging (email@example.com:staging/my-repo.git), however is non-negotiable as that’s pointing to a physical location on the server. That will always be either
production, based on which remote you want to set up.
Once you’ve successfully added a remote repository, you can open up your
.git/config file in your local repository and you’ll see a reference to your remote(s).
The deploy step is the last one in the chain – this is where you push the code from your local repository to the corresponding remote repository on WP Engine.
You’ll deploy to your remote server from the command land at the folder location of the repo you want to deploy. That might sound obvious, but I know when I’m trying to get the hang of something new I always appreciate extra-explicit instruction!
An example git push looks like this:
git push staging master
In this example,
git push is the command,
staging is the name of the remote, and
master is the branch of your local repository you want to push.
If you run into trouble, check out WP Engine’s tutorial:
Extra Info about using Git Push with WP Engine
Version WordPress Core (or Not)
Many smarter people than me have debated the merits of keeping WordPress core files under version control, so I’m not going to get into that here.
I’m only mentioning it to say that with WP Engine you have the option to throw WordPress under version control.
WP Engine has some sample .gitignore files (look for the “Setting up the .gitignore…” section) you can use based on whether or not you want to version WP core files.
No Composer Support (Yet)
I’ve taken to using Composer on WordPress projects. If you’re not familiar with it, it’s a PHP dependency manager, which is a fancy way of saying “this project requires these other code libraries to work properly.” In the case of WordPress, these code libraries are typically plugins.
I can wax about the benefits of Composer in another post, but for the purposes of this discussion, WP Engine does not support Composer.
Word on the street is this capability might happen at some point, but until then, if you want to do any sort of builds post-push, you’ll need to use Git sub-modules instead. Note that sub-modules only work with publicly-available repos (H/T to Ryan Hoover for that info!)
You Can Still Use SFTP (with caution)
If you want to access or make changes to your uploads, themes, and plugins via SFTP, be sure to exclude those from your git repo in your .gitignore file. Otherwise, if you make changes to source-controlled files via SFTP, they’ll be overwritten on the next push.
A Nice Discount for My Friends 🙂
If you haven’t tried out WP Engine yet, today is your day. Get 20% off your first payment with coupon code wpe20off and an extra 2 months free if you sign up for an annual plan.
The most basic hosting plan (Personal) includes git push integration, staging sites, transferrable installs (for passing billing to a client), and more.
Go on now, git goin!