Being relatively new to version control, figuring out WP Engine’s Git Push feature was a daunting challenge at first. Reading through multiple guides and resources while structuring my own process around my findings was not an easy task. This guide explains my process of using Git with WP Engine by:
- Covering how to setup your remote repository with WP Engine
- Explaining a few key features in version control
- Detailing how to push local files to the WP Engine server.
If you already have a strong grasp of how Git works, you can skip ahead to: Configuring Git for your WP Engine install.
Generate an SSH Key
You only have to generate an SSH key once for each machine you plan on working from. If you have already done this skip below to Initializing Git.
Github has a great article on how to generate an SSH key which can be found here:
https://help.github.com/articles/generating-ssh-keys/
Initializing Git
After setting up a fresh local WordPress install you need to add a .gitignore before initializing your Git repo. This is to make sure Git tracks only the necessary files and not the entire WordPress install.
Navigate to the root directory of your website in Terminal and enter the following command in order to make a blank .gitignore file:
touch .gitignore
Open the file in a text editor using the command:
open .gitignore -a "Sublime Text"
Paste in WP Engine’s recommended .gitignore and save the file. I personally keep it bookmarked in my toolbar.
Initialize your repo using:
git init
Using Git
Switch to a development branch using:
git checkout -b "development"
You should always be working off of a development branch in case something goes wrong. This way you will have the clean install in the master branch to revert back to.
Basic Snapshotting
After making changes to any of your files, view what files have changed and are unstaged using:
git status
Add all untracked and modified files to the staging area in order to commit them
git add -A
With the content you want to commit staged, run a commit to record what’s called a ‘snapshot’:
git commit -m "Insert description of changes here"
Don’t Forget To Use Branches
When creating a new feature, create and checkout a new branch using:
git checkout -b "name_of_feature_branch"
See what branch you are on and what other branches exist:
git branch
Merge files back to master branch when everything is 100% working and operational:
git checkout "name_of_master_branch"
git merge "name_of_branch_you_are_merging"
To gain a better understanding of how Git works and the numerous features it has to offer, check out this simple guide:
http://rogerdudler.github.io/git-guide/
Configuring Git for your WP Engine install
Now we have to make sure your computer is synced up to WP Engine in order for you to push your local files.
Copy your SSH key to your clipboard.
Enter the following command into Terminal:
pbcopy < ~/.ssh/id_rsa.pub
Add the SSH Public Key to Git Push on WP Engine
Enter a developer name that will be used consistently, give it a name specific to what device you will be pushing from.
Paste the SSH key that is in your clipboard.
Test the connection
Enter the following command into Terminal:
ssh git@git.wpengine.com info
Setup the git remote
Navigate to the website’s theme directory:
cd Documents/Websites/www.mywebsite.dev/wp-content/themes/themename
Enter the following command into Terminal, replacing "my_wp_install_name" with the name of your WP Engine install:
git remote add production git@git.wpengine.com:production/my_wp_install_name.git
Confirm it was added:
git remote -v
Deploy to WP Engine
Enter the following command into Terminal:
git push production master
WP Engine has two great guides on this that go more in-depth and they can be found here:
https://wpengine.com/support/set-git-push-user-portal/
https://wpengine.com/git/
Questions or comments about how your workflow differs? Leave a comment below.
Leave a Reply