31
A Workflow A7 Web Design, Owner [email protected] $ Aaron Holbrook WordPress and Version Control Monday, June 11, 12

WordPress & Version Control: A Workflow

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

Page 1: WordPress & Version Control: A Workflow

A Workflow

A7 Web Design, [email protected]

$ Aaron Holbrook

WordPress  and  Version  Control

Monday, June 11, 12

Page 2: WordPress & Version Control: A Workflow

#wcmke #wpgit

@aaronjholbrook

[email protected]

a7web.com

Monday, June 11, 12

Page 3: WordPress & Version Control: A Workflow

#wcmke #wpgit

overviewBackgroundDisclaimer

AssumptionsLocal Development

Version Control (Git)

Using WordPress & Git togetherDeployment

Some demosAsk questions!

Monday, June 11, 12

Page 4: WordPress & Version Control: A Workflow

#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

Page 5: WordPress & Version Control: A Workflow

#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

Page 6: WordPress & Version Control: A Workflow

#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

Page 7: WordPress & Version Control: A Workflow

#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

Page 8: WordPress & Version Control: A Workflow

#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

Page 9: WordPress & Version Control: A Workflow

#wcmke #wpgit

things you’ll need

Terminal

Git

SSH

Monday, June 11, 12

Page 10: WordPress & Version Control: A Workflow

#wcmke #wpgit

legend

Whenever you see

Everything after the is what you should type

$ command here

$

Monday, June 11, 12

Page 11: WordPress & Version Control: A Workflow

“A civilized tool for a civilized age”- Si, stack overflow

Monday, June 11, 12

Page 12: WordPress & Version Control: A Workflow

#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

Page 13: WordPress & Version Control: A Workflow

#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

Page 14: WordPress & Version Control: A Workflow

#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

Page 15: WordPress & Version Control: A Workflow

DeployMonday, June 11, 12

Page 16: WordPress & Version Control: A Workflow

#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

Page 17: WordPress & Version Control: A Workflow

#wcmke #wpgit

wp-config.local.phpthis file is the magic key

Monday, June 11, 12

Page 18: WordPress & Version Control: A Workflow

#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

Page 19: WordPress & Version Control: A Workflow

#wcmke #wpgit

wp-config.php

Monday, June 11, 12

Page 20: WordPress & Version Control: A Workflow

#wcmke #wpgit

ssh 101

1.

2. Enter password

3.

$ ssh [email protected]

success

Monday, June 11, 12

Page 21: WordPress & Version Control: A Workflow

#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

Page 22: WordPress & Version Control: A Workflow

#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

Page 23: WordPress & Version Control: A Workflow

#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

Page 24: WordPress & Version Control: A Workflow

#wcmke #wpgit

hookHUB/git-hub/hooks/post-update

Monday, June 11, 12

Page 25: WordPress & Version Control: A Workflow

#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

Page 26: WordPress & Version Control: A Workflow

#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

Page 27: WordPress & Version Control: A Workflow

#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

Page 28: WordPress & Version Control: A Workflow

#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

Page 29: WordPress & Version Control: A Workflow

#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

Page 30: WordPress & Version Control: A Workflow

#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

Page 31: WordPress & Version Control: A Workflow

#wcmke #wpgit

@aaronjholbrook

a7web.com

[email protected], June 11, 12