Upload
aaron-holbrook
View
114
Download
1
Embed Size (px)
DESCRIPTION
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!
Citation preview
A Workflow
A7 Web Design, [email protected]
$ Aaron Holbrook
WordPress and Version Control
Monday, June 11, 12
#wcmke #wpgit
@aaronjholbrook
a7web.com
Monday, June 11, 12
#wcmke #wpgit
overviewBackgroundDisclaimer
AssumptionsLocal Development
Version Control (Git)
Using WordPress & Git togetherDeployment
Some demosAsk questions!
Monday, June 11, 12
#wcmke #wpgit
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?
Monday, June 11, 12
#wcmke #wpgit
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
Monday, June 11, 12
#wcmke #wpgit
disclaimer!
This workflow is something that I’ve refined to suit my needs, feel free to adjust it to suit yours
YMMV (your mileage may
vary)
Monday, June 11, 12
#wcmke #wpgit
assumptionsYou’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
You have a local development environment that you prefer to work within
You’d like to have seamless, simple deployments
(most hosts support SSH, sometimes you have to ask)
Monday, June 11, 12
#wcmke #wpgit
the workflow
Start local, develop some functionality
Set up deployment system to your live server
Deploy your changes with the press of a button!
Monday, June 11, 12
#wcmke #wpgit
things you’ll need
Terminal
Git
SSH
Monday, June 11, 12
#wcmke #wpgit
legend
Whenever you see
Everything after the is what you should type
$ command here
$
Monday, June 11, 12
“A civilized tool for a civilized age”- Si, stack overflow
Monday, June 11, 12
#wcmke #wpgit
git 101
You can define a Git repository in any directory simply by typing:
Via the terminal, navigate to the root of your local site directory and type
$ git init
$ git init
Monday, June 11, 12
#wcmke #wpgit
.gitignore.DS_Storewp-config.local.php
.htaccess
wp-content/uploads/
wp-content/cache/
Optional - ignore user uploads
Optional - ignore live cache
Monday, June 11, 12
#wcmke #wpgit
git 102
In your git repo, add all files
Commit!
$ git add .
$ git commit -m “Commit Message”
-m allows an inline commit messageSuccess!
Monday, June 11, 12
DeployMonday, June 11, 12
#wcmke #wpgit
wp-config.local.php
1. Define local variables without contaminating the server
2. Add a call to to check for this file and load it if it exists
Credit to Mark Jaquith who came up with this ideahttp://markjaquith.wordpress.com/2011/06/24/wordpress-local-dev-tips/
this file is the magic key
wp-config.php
Monday, June 11, 12
#wcmke #wpgit
wp-config.local.phpthis file is the magic key
Monday, June 11, 12
#wcmke #wpgit
wp-config.php
1. Test for
2. If it doesn’t exist, then use live server connection information
wp-config.local.php
Monday, June 11, 12
#wcmke #wpgit
wp-config.php
Monday, June 11, 12
#wcmke #wpgit
&
On the server, we will create two repositories
will be the main collaborator
will be the live site repository
HUB
PRIME
HUB PRIME
Major props to Joe Mallerhttp://joemaller.com/990/a-web-focused-git-workflow/
Monday, June 11, 12
#wcmke #wpgit
hub
Create hub as a bare repository
$ git init --bare
/domains/site.com/html
/domains/site.com/git-hub
HUB
I generally put it right above the site’s html root in a ‘git-hub’* folder
* Not to be confused with the fantastic GitHub websitehttps://github.com/
Monday, June 11, 12
#wcmke #wpgit
hook
We’ll want to auto-update when we push our changes up to H
So let’s set up a hook!
PRIME
HUB
HUB
Monday, June 11, 12
#wcmke #wpgit
hookHUB/git-hub/hooks/post-update
Monday, June 11, 12
#wcmke #wpgit
1. Create as regular repo
2. Add remote to
$ git init
$ git remote add hub /domains/site.com/git-hub
PRIME
HUB
Monday, June 11, 12
#wcmke #wpgit
and finally
Set up our local remote to
$ git remote add hub ssh://[email protected]/home/domains/site.com/git-hub
HUB
Success!
Monday, June 11, 12
#wcmke #wpgit
3...2...1... blast off !Make sure that our repository is clean
...wait for it...
We’ve deployed!
$ git add .
$ git commit -am “Updated header to include nav links”
$ git push hub master
hooray!
Monday, June 11, 12
#wcmke #wpgit
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
Monday, June 11, 12
#wcmke #wpgit
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 frequently
caution!
/uploads/*
Monday, June 11, 12
#wcmke #wpgit
take away
Start local, develop some functionality
Set up deployment system to your live server
Deploy your changes with the press of a button!
Monday, June 11, 12