Git Push with WP Engine

## Metadata
- Author: [[Carrie Dils]]
- Full Title: Git Push with WP Engine
- Category: #articles
- Summary: 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.
- URL: https://carriedils.com/git-push-wp-engine/
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](http://wpeng.in/carrie/) 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](http://deploybot.com/) 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](https://carriedils.com/saas-software-reviews/) 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](https://git-scm.com/book/en/v2/Git-on-the-Server-Generating-Your-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](https://help.github.com/articles/checking-for-existing-ssh-keys/)). Otherwise, you can [create a new SSH key](https://help.github.com/articles/generating-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 protected] 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 protected] 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:
**RSA** 19:17:ee:d2:1d:8d:c9:3e:dc:3e:0d:21:a7:c6:52:fc
**ECDSA** 0c:4b:07:92:dd:e0:be:50:90:7d:0d:c3:30:56:fa:9a
**ECDSA** SHA256 Jgp8bPftGbM0rzQaeA7KTBrZa1UfEN1nqQMLIwu5i18
If it doesn’t match, don’t continue the connection. Here’s the [documentation](https://wpengine.com/git/) 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 `.git` folder).
`cd ~/path/to/my-repo`
**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](http://www.macworld.com/article/1161876/open_finder_folder_in_terminal.html).**
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 protected]:**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 protected]:staging/my-repo.git)`, however is non-negotiable as that’s pointing to a physical location on the server. That will always be either `staging` or `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).
#### Deploy
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`](https://git-scm.com/docs/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](https://wpengine.com/git/) (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](https://getcomposer.org/) 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](http://wpeng.in/carrie/).
The most basic hosting plan (Personal) includes git push integration, [staging sites](https://carriedils.com/wp-engine-staging-sites/), transferrable installs (for passing billing to a client), and more.
Go on now, git goin!, Git Push with WP Engine, Carrie Dils, 01gnmcy96trtem50ze0hr1rvta.