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
You may already have a key generated on your machine, in which case you can use that (here’s how you check for existing SSH keys). Otherwise, you can create a new 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 email@example.com 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 firstname.lastname@example.org 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 email@example.com: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 (firstname.lastname@example.org: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) WP Engine supports Composer
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.
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 3 months free with an annual plan with coupon code WPE3FREE.
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!
9 thoughts on “Git Push with WP Engine”
One related tip: if you frequently use SSH to connect to the same hosts, you can set up a ~/.ssh/config file and include your hosts in that file (along with their IP address, port, username, path to your SSH key, etc). Then you can just type “ssh foo” going forward => keystrokes saved 🙂
I wrote up a short blurb about it awhile back for anyone wanting more info: http://sheelahb.com/blog/productivity-tip-number-1-use-ssh-aliases-for-frequently-visited-hosts/
Great tip – thanks for sharing!
Hello Carrie Ma,am,
happy to meet you here.. 🙂
Very informative and suggestive article for us.. you know. I like this post after reading and knowing something about this through your post.
Informative points are easy to understand for me. And therefore, I can’t hold myself to commenting on this article.. you know ma,am.
Thanks a lot for guiding through your interesting article.. 🙂
Have a good day..
Thanks, Ravi! I’m glad you enjoyed it!
Hey Carrie – one more thing to note with WPE git. You’re pushing to the repo but that repo is then rsynced to the staging or production server. So the repo is not a true reflection of what’s on a site, as any updates on, say the live site, don’t appear in the live site’s repo.
It looks like this isn’t the case now. From https://wpengine.co.uk/git/ … “We can and will continue to keep your application’s WordPress install up-to-date – it’s just easier if the repository doesn’t contain WordPress core files. If it does, we will commit and push the WordPress core upgrade back to your repo.”
They don’t allow pushing images apparently?
I found this out today setting up a staging for a client.
Coming from Wordmove and RunCloud this seems like a big limitation, and means I would still have to resort to FTP.
Are they uploaded images (i.e. in
wp-content/uploads/) or part of your theme files? Did you contact WPE support? Seems like you should be able to push/pull images so long as they’re under version control.
Pingback: Nexcess Managed WordPress Hosting Review