Slide 1

Slide 1 text

WordPress & Version Control Aaron Holbrook

Slide 2

Slide 2 text

@aaronjholbrook [email protected] a7web.com me

Slide 3

Slide 3 text

Full-time Freelance Web Developer (1.5yr) Web Developer & WordPress fanatic since 2005 Father, husband, gamer, geek AARON HOLBROOK

Slide 4

Slide 4 text

BACKGROUND Webmaster (5yrs) for a Hospital Saved Hospital >$400,000 Built a network of Git repos/remotes

Slide 5

Slide 5 text

CURRENTLY Founded and run A7 Web Design (3yrs) Global client base Theme & Plugin Author Core contributor Automation Script Builder Founded McHenry County WordPress Meetup

Slide 6

Slide 6 text

OVERVIEW WTF is version control? Why should I care? Use it TODAY! WP & Version Control: A match made in heaven

Slide 7

Slide 7 text

WHAT IS VERSION CONTROL? $version_control = “A system that tracks changes to your files over time”;

Slide 8

Slide 8 text

EVER DONE THIS?

Slide 9

Slide 9 text

YOU’RE A GENIUS! you made your own (rudimentary) version control system!!!

Slide 10

Slide 10 text

WHY USE IT? PREVENT THE FOLLOWING

Slide 11

Slide 11 text

code y u no work anymore?

Slide 12

Slide 12 text

backup? what backup?

Slide 13

Slide 13 text

seriously though...

Slide 14

Slide 14 text

Incremental backups Short & long term undo Easier collaboration Track changes & ownership Sandboxing BE A BETTER DEV

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Lightning fast Distributed Easy Branching Easy team collaboration WHY GIT?

Slide 17

Slide 17 text

!= version control system collaborative coding web app

Slide 18

Slide 18 text

TERMS REPO: The database storing the files COMMIT: A snapshot of your files in time

Slide 19

Slide 19 text

Committed Modified Staged THREE STATES OF EXISTENCE (for files)

Slide 20

Slide 20 text

Safely stored in Git database COMMITTED

Slide 21

Slide 21 text

File has been modified, but hasn’t been committed yet MODIFIED

Slide 22

Slide 22 text

File is marked to go into your next commit STAGED

Slide 23

Slide 23 text

Working Directory Git Directory Staging Area THREE SECTIONS OF A GIT REPOSITORY

Slide 24

Slide 24 text

This is where Git stores the metadata and object database for the project GIT DIRECTORY

Slide 25

Slide 25 text

A single checkout of one version of the project WORKING DIRECTORY

Slide 26

Slide 26 text

A file that contains information about what will go in the next commit STAGING AREA

Slide 27

Slide 27 text

Modify files Stage files Commit! GIT WORKFLOW

Slide 28

Slide 28 text

Install http://git-scm.com/downloads GIT STARTED

Slide 29

Slide 29 text

Configure GIT STARTED $ git config --global user.name “Aaron Holbrook” $ git config --global user.email “[email protected]

Slide 30

Slide 30 text

Create a Git repository in ANY directory $ git init Even existing projects!! INITIALIZE

Slide 31

Slide 31 text

Add our files to the staging area $ git add . ADD ALL THE THINGS!!1

Slide 32

Slide 32 text

Commit our snapshot to the repository $ git commit -m “Initial Commit” COMMIT

Slide 33

Slide 33 text

Congratulations! You’ve successfully created a Git repository and committed a permanent snapshot of your files! YOU ROCK!

Slide 34

Slide 34 text

FASTEN YOUR SEATBELTS

Slide 35

Slide 35 text

VIEWING COMMITS $ git log

Slide 36

Slide 36 text

Roll back to previous commits $ git checkout db210f ROLLBACK

Slide 37

Slide 37 text

Create a branch (sandbox!) $ git branch NewBranch $ git checkout NewBranch $ git checkout master BRANCHING ...do some experiments, decide that we want to go back to where its safe:

Slide 38

Slide 38 text

MERGING BRANCHES Commit changes on a branch $ git commit -m “NewBranch commit” $ git checkout master $ git merge NewBranch Check out the branch you wish to merge into Merge the branches!

Slide 39

Slide 39 text

OH NOES! A WILD MERGE CONFLICT APPEARS!!

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

Customized Log Output: https://gist.github.com/3453149

Slide 45

Slide 45 text

WHEW! DISASTER AVERTED!

Slide 46

Slide 46 text

WORDPRESS & VERSION CONTROL Now with multiple environments!

Slide 47

Slide 47 text

DEPLOY WORKFLOW Development Environment Set up remotes to live server Deploy changes!

Slide 48

Slide 48 text

Special file: .gitignore Goes in the root of your repo Add filenames or directories that Git should ignore .GITIGNORE

Slide 49

Slide 49 text

.GITIGNORE wp-config.local.php .DS_Store/Thumbs.db .htaccess wp-content/uploads/ wp-content/cache/ Optional - ignore user uploads Optional - ignore live cache

Slide 50

Slide 50 text

WP-CONFIG.LOCAL.PHP Define dev DB info Keeps dev DB separate from production DB this file is the magic key Credit to Mark Jaquith (@markjaquith) http://markjaquith.wordpress.com/2011/06/24/wordpress-local-dev-tips/

Slide 51

Slide 51 text

Test for If it exists, use it If not, use Production DB info WP-CONFIG.PHP wp-config.local.php

Slide 52

Slide 52 text

WP-CONFIG.PHP

Slide 53

Slide 53 text

PASSWORDLESS SSH a@A:$ ssh-keygen -t rsa a@A:$ ssh b@B mkdir -p .ssh a@A:$ cat .ssh/id_rsa.pub | ssh b@B ‘cat >> .ssh/authorized_keys’

Slide 54

Slide 54 text

Create two repositories on Production: -> collaboration (central hub) repo -> live site repo HUB PRIME Thanks to Joe Maller http://joemaller.com/990/a-web-focused-git-workflow/ HUB & PRIME

Slide 55

Slide 55 text

$ git init --bare /domains/site.com/html /domains/site.com/git-hub Place outside of root in a ‘git-hub’* folder *Not to be confused with the fantastic GitHub https://github.com/ HUB

Slide 56

Slide 56 text

HOOK IT UP Hooks allow you to run bash scripts upon certain criteria (a lot like WordPress!) We’ll want to create a hook so HUB updates PRIME automatically

Slide 57

Slide 57 text

HOOKS Located in .git/hooks applypatch-msg commit-msg post-update pre-applypatch pre-commit pre-rebase prepare-commit-msg update

Slide 58

Slide 58 text

POST-UPDATE HOOK Fires after receiving a push from a remote /git-hub/hooks/post-update

Slide 59

Slide 59 text

/domains/site.com/html PRIME $ git init $ git remote add hub /domains/site.com/git-hub Secure the .git directory with .htaccess!

Slide 60

Slide 60 text

$ git remote add hub ssh://[email protected]/home/domains/site.com/git-hub DEVELOPMENT ENVIRONMENT Add a remote from DEV to HUB

Slide 61

Slide 61 text

DEPLOY! $ git add . $ git commit -am “Updated header to include nav links” $ git push hub master

Slide 62

Slide 62 text

DEPLOY SUCCESSFUL!

Slide 63

Slide 63 text

PUSH / PULL $ git pull hub master If you make any changes directly on PRIME you will need to commit on PRIME and PULL to PRODUCTION

Slide 64

Slide 64 text

CAUTION! If you did NOT put the wp-content/uploads folder in .gitignore, you will have to manually commit changes frequently

Slide 65

Slide 65 text

PRETTY MUCH THIS Version control is amazing! It will improve your life! Using the basics is simple! Google is your friend!

Slide 66

Slide 66 text

aaronjholbrook.com/?p=310 Slides @aaronjholbrook a7web.com [email protected] #wpgit #wcchi