I’ve spent quite a bit of time refining and perfecting my development workflow. I’d like to share how I use WordPress with version control to still develop locally and easily push changes live with the push of a button. No more dragging files into FTP! No more losing changes because of stupid accidents!
Powerful Google developer tools for immediate impact! (2023-24 C)
WordPress & Version Control: A Workflow
1. WordPress and
Version Control
A Workflow
$ Aaron Holbrook
A7 Web Design, Owner
aaron@a7web.com
Monday, June 11, 12
2. aaron@a7web.com
@aaronjholbrook
a7web.com
#wcmke #wpgit
Monday, June 11, 12
3. overview
Background
Disclaimer
Assumptions
Local Development
Version Control (Git)
Using WordPress & Git together
Deployment
Some demos
Ask questions!
#wcmke #wpgit
Monday, June 11, 12
4. have you ever...
Wanted to make your changes live with the push of a
button?
Hated dragging files into FTP and wished for a better way?
Been editing via FTP, made a change, closed the editor
and immediately realized you shouldn’t have closed it?
Lost code and didn’t have a backup?
Had a backup, but it was too old?
Had a site become corrupt, infected or lost with no way to
recover it?
#wcmke #wpgit
Monday, June 11, 12
5. a little history
I had 10+ WordPress sites to maintain
Sites were similar in layout and style
differing only by color scheme
Needed a way to quickly push out
changes across all the sites
Really wanted to utilize version control
#wcmke #wpgit
Monday, June 11, 12
6. disclaimer!
ma y vary)
ileage
YMMV (your m
This workflow is something that I’ve
refined to suit my needs, feel free to
adjust it to suit yours
#wcmke #wpgit
Monday, June 11, 12
7. assumptions
You’re aware of how important Version Control is,
but have not fully integrated it into your workflow
You have some familiarity with the command line
Your live server environment supports SSH
(most hosts support SSH, sometimes you have to ask)
You have a local development environment that
you prefer to work within
You’d like to have seamless, simple deployments
#wcmke #wpgit
Monday, June 11, 12
8. the workflow
Start local, develop some functionality
Set up deployment system to your live
server
Deploy your changes with the press of a
button!
#wcmke #wpgit
Monday, June 11, 12
10. legend
Whenever you see $ command here
Everything after the $ is what you should
type
#wcmke #wpgit
Monday, June 11, 12
11. “A civilized tool for a civilized age”
- Si, stack overflow
Monday, June 11, 12
12. git 101
You can define a Git repository in any
directory simply by typing: $ git init
Via the terminal, navigate to the root of
your local site directory and type $ git init
#wcmke #wpgit
Monday, June 11, 12
13. .gitignore
.DS_Store
wp-config.local.php
.htaccess
Optional - ignore user uploads
wp-content/uploads/
Optional - ignore live cache
wp-content/cache/
#wcmke #wpgit
Monday, June 11, 12
14. git 102
In your git repo, add all files $ git add .
Commit! $ git commit -m “Commit Message”
Success! -m allows an i
nline commit m
essage
#wcmke #wpgit
Monday, June 11, 12
16. this
file
is t
wp-config.local.php
he m
agic
key
1. Define local variables without
contaminating the server
2. Add a call to wp-config.php to check for
this file and load it if it exists
Credit to Mark Jaquith who came up with this idea
#wcmke #wpgit http://markjaquith.wordpress.com/2011/06/24/wordpress-local-dev-tips/
Monday, June 11, 12
17. this
file
is t
wp-config.local.php
he m
agic
key
#wcmke #wpgit
Monday, June 11, 12
18. wp-config.php
1. Test for wp-config.local.php
2. If it doesn’t exist, then use live server
connection information
#wcmke #wpgit
Monday, June 11, 12
20. ssh 101
1. $ ssh login@server.com
2. Enter password
3. success
#wcmke #wpgit
Monday, June 11, 12
21. HUB & PRIME
On the server, we will create two
repositories
HUB will be the main collaborator
PRIME will be the live site repository
Major props to Joe Maller
#wcmke #wpgit http://joemaller.com/990/a-web-focused-git-workflow/
Monday, June 11, 12
22. hub
HUB
Create hub as a bare repository
I generally put it right above the site’s html root in a ‘git-hub’* folder
/domains/site.com/html
/domains/site.com/git-hub
$ git init --bare
* Not to be confused with the fantastic GitHub website
#wcmke #wpgit https://github.com/
Monday, June 11, 12
23. HUB hook
We’ll want PRIME to auto-update when we
push our changes up to H HUB
So let’s set up a hook!
#wcmke #wpgit
Monday, June 11, 12
24. HUB hook
/git-hub/hooks/post-update
#wcmke #wpgit
Monday, June 11, 12
25. PRIME
1. Create as regular repo
$ git init
2. Add remote to HUB
$ git remote add hub /domains/site.com/git-hub
#wcmke #wpgit
Monday, June 11, 12
26. and finally
Set up our local remote to HUB
$ git remote add hub ssh://login@host.com/home/domains/site.com/git-hub
Success!
#wcmke #wpgit
Monday, June 11, 12
27. 3...2...1... blast off!
Make sure that our repository is clean
$ git add .
$ git commit -am “Updated header to include nav links”
...wait for it...
$ git push hub master
We’ve deployed! hooray!
#wcmke #wpgit
Monday, June 11, 12
28. push & pull
Occasionally you will need to commit on
the server and pull down to your local
repository
All you need to do (from local machine)
$ git pull hub master
#wcmke #wpgit
Monday, June 11, 12
29. caution!
The uploads folder can change quite
frequently, which may cause your repos to
get out of sync, necessitating a need for
frequent pulldowns to keep repos in
check
Depending on situation, you can ignore
uploads/* directory or sync repos
/uploads/*
frequently
#wcmke #wpgit
Monday, June 11, 12
30. take away
Start local, develop some functionality
Set up deployment system to your live
server
Deploy your changes with the press of a
button!
#wcmke #wpgit
Monday, June 11, 12
31. a7web.com
@aaronjholbrook
aaron@a7web.com
#wcmke #wpgit
Monday, June 11, 12