Deploy to WPEngine Using Git Push
Sometimes you can think something is more complicated than it is. And sometimes you get beaten down by the fear or the overwhelm of a concept. That’s why I have created this article. It breaks down the simplicity of WPengine gitpush
.
WP Engine provides a Git Push integration that allows you to deploy your WordPress site by pushing changes to a Git repository. Here’s a simple guide to set up deployment using Git push on WP Engine:
Prerequisites
- You have a WPEngine account with a website installed already on WPEngine
- You know how to use terminal
1. Generate SSH key
If you don’t already have an SSH key that you can use. You’ll we want to generate a new ssh key one and add it to WP engine.
2. Add your key to your Site
Locate your site from your list of sites in your wpengine account. The key will typically be published approximately 10 minutes after saving, but may take as long as 45 minutes. There will be an error if connecting to Git before the key is fully published. Select your Site to pull up the admin for that specific install.
Check what sites you have already added your key to
This will return a list of sites you can read and write to
1
ssh git@git.wpengine.com info
The key must be added to each environment independently to use Git Push.
Select the GitPush
link in the side menu for the your choosen enviroment (production, staging, dev) When you add your key (give it a name). You will get back a unique remote url for environment you just added the key to.
3. Get the enviroment Git Remote URL
After adding your public ssh key. You’ll then have access to the remote git repo url. Copy the git repo remote url.
4. Create your local
Initialize a Git repository in your local WordPress project if you haven’t already.
Set Up Local Git Repository:
cd to your project root. Dont worry we are going to ignore almost everything.
1
2
3
git init
git add .
git commit -m "Initial commit"
5. Add your remote repo url to your local repo
Here we are adding a remote and the name we give to the remote is staging
.
1
git remote add staging git@git.wpengine.com:your-remote-repo-url.git
Optional - Add a Github Repo
If you want a visual repo you can also add a remote for a github repo.
1
git remote add gitrepo git@github.com:pixelstorm/repo-name.git
6. Add Gitignore
As your local repo is initiated in the root directory a .gitignore
is essential for only deploying the parts your want. 90% of the time we personally want to exclude everything in the gitignore file except for the theme files.
See gitignore from wpengine
remember to exclude your node_modules folder if you have one(because their is like a billion files in there you dont need to deploy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
*~
.DS_Store
.svn
.cvs
*.bak
*.swp
Thumbs.db
# wordpress specific
wp-config.php
wp-content/uploads/
wp-content/blogs.dir/
wp-content/upgrade/*
wp-content/upgrade-temp-backup/*
wp-content/backup-db/*
wp-content/advanced-cache.php
wp-content/wp-cache-config.php
wp-content/cache/*
wp-content/cache/supercache/*
# wpengine specific
.smushit-status
.gitattributes
_wpeprivate*
wp-content/object-cache.php
wp-content/mu-plugins/mu-plugin.php
wp-content/mu-plugins/slt-force-strong-passwords.php
wp-content/mu-plugins/stop-long-comments.php
wp-content/mu-plugins/force-strong-passwords*
wp-content/mu-plugins/wpengine-common*
wp-content/mysql.sql
wp-content/mu-plugins/wpengine-security-auditor.php
wp-content/mu-plugins/wpe-wp-sign-on-plugin*
# wp core (as of 4.9.5)
/db-config.php
/index.php
/license.txt
/readme.html
/wp-activate.php
/wp-app.php
/wp-atom.php
/wp-blog-header.php
/wp-comments-post.php
/wp-commentsrss2.php
/wp-config-sample.php
/wp-cron.php
/wp-feed.php
/wp-links-opml.php
/wp-load.php
/wp-login.php
/wp-mail.php
/wp-rdf.php
/wp-rss.php
/wp-rss2.php
/wp-pass.php
/wp-register.php
/wp-settings.php
/wp-signup.php
/wp-trackback.php
/xmlrpc.php
/wp-admin
/wp-includes
/wp-content/index.php
/wp-content/themes/twentyten
/wp-content/themes/twentyeleven
/wp-content/themes/twentytwelve
/wp-content/themes/twentythirteen
/wp-content/themes/twentyfourteen
/wp-content/themes/twentyfifteen
/wp-content/themes/twentysixteen
/wp-content/themes/twentyseventeen
/wp-content/themes/twentyeighteen
/wp-content/themes/twentynineteen
/wp-content/themes/twentytwenty
/wp-content/themes/twentytwentytwo
/wp-content/themes/index.php
/wp-content/plugins/*
# large/disallowed file types
# a CDN should be used for these
*.hqx
*.bin
*.exe
*.dll
*.deb
*.dmg
*.iso
*.img
*.msi
*.msp
*.msm
*.mid
*.midi
*.kar
*.mp3
*.ogg
*.m4a
*.ra
*.3gpp
*.3gp
*.mp4
*.mpeg
*.mpg
*.mov
*.webm
*.flv
*.m4v
*.mng
*.asx
*.asf
*.wmv
*.avi
7. Push Changes to WP Engine:
Use git push to deploy your WordPress site to WP Engine. In this example we push all files to the staging remote. staging
is the name of the repo we gave when ae added the staging remote.
1
git push -v staging master
This example shows whats actually happening here
1
git push -v remote-name branch-name
The benefits of Git Push
Apart from efficincy and having a process for deployment. Git Push also clears your caching for you. Which is great as WPE has a sophisticated caching system that can often get in the way of development.
Git pull with multiple remotes
When you run git pull
and you have multiple remotes, Git fetches from all remotes by default, but it only merges or rebases the currently checked-out branch with its corresponding upstream branch.
Here’s what happens in more detail:
- Fetching: Git fetches the latest changes from all remotes. It retrieves all the new commits and updates the remote tracking branches (origin/master, for example) for each remote.
- Merging or Rebasing: If you’re on a branch that’s set up to track a remote branch, Git will merge or rebase the changes from the corresponding remote branch into your current branch. If there are conflicts, you’ll need to resolve them.
- Updating the Working Directory: After successfully merging or rebasing, Git updates your working directory with the changes. This means your local files will reflect the updates from the remote repository.
It’s worth noting that git pull is essentially a combination of git fetch and either git merge or git rebase, depending on your configuration. You can specify the remote and branch to pull from using the syntax git pull
Trouble Shooting
- If there is some deployment issue with Git Push which requires you to update your gitignore. Sometimes the new changes to gitignore does not work as the old version is stored in cache. You need to clear the git cache.
1
2
3
4
5
git rm -r --cached .
git add .
git commit -m "clear git cache"
git push
- large files will not deploy to wpengine