WordPress & Version Control (v2) - WordCamp Chicago 2012

WordPress & Version Control (v2) - WordCamp Chicago 2012

Version Control lets you track your files over time. Why should you care? So when you mess up you can easily get back to a previous working version! I will take you through what version control is, why it’s important and how to start using it today on projects you’re already working on.

B727d9a86047391aab86fdb87dc6c313?s=128

Aaron Holbrook

August 25, 2012
Tweet

Transcript

  1. WordPress & Version Control Aaron Holbrook

  2. @aaronjholbrook aaron@a7web.com a7web.com me

  3. Full-time Freelance Web Developer (1.5yr) Web Developer & WordPress fanatic

    since 2005 Father, husband, gamer, geek AARON HOLBROOK
  4. BACKGROUND Webmaster (5yrs) for a Hospital Saved Hospital >$400,000 Built

    a network of Git repos/remotes
  5. CURRENTLY Founded and run A7 Web Design (3yrs) Global client

    base Theme & Plugin Author Core contributor Automation Script Builder Founded McHenry County WordPress Meetup
  6. OVERVIEW WTF is version control? Why should I care? Use

    it TODAY! WP & Version Control: A match made in heaven
  7. WHAT IS VERSION CONTROL? $version_control = “A system that tracks

    changes to your files over time”;
  8. EVER DONE THIS?

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

    system!!!
  10. WHY USE IT? PREVENT THE FOLLOWING

  11. code y u no work anymore?

  12. backup? what backup?

  13. seriously though...

  14. Incremental backups Short & long term undo Easier collaboration Track

    changes & ownership Sandboxing BE A BETTER DEV
  15. “A civilized tool for a civilized age” - Si, stack

    overflow
  16. Lightning fast Distributed Easy Branching Easy team collaboration WHY GIT?

  17. != version control system collaborative coding web app

  18. TERMS REPO: The database storing the files COMMIT: A snapshot

    of your files in time
  19. Committed Modified Staged THREE STATES OF EXISTENCE (for files)

  20. Safely stored in Git database COMMITTED

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

  22. File is marked to go into your next commit STAGED

  23. Working Directory Git Directory Staging Area THREE SECTIONS OF A

    GIT REPOSITORY
  24. This is where Git stores the metadata and object database

    for the project GIT DIRECTORY
  25. A single checkout of one version of the project WORKING

    DIRECTORY
  26. A file that contains information about what will go in

    the next commit STAGING AREA
  27. Modify files Stage files Commit! GIT WORKFLOW

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

  29. Configure GIT STARTED $ git config --global user.name “Aaron Holbrook”

    $ git config --global user.email “aaron@a7web.com”
  30. Create a Git repository in ANY directory $ git init

    Even existing projects!! INITIALIZE
  31. Add our files to the staging area $ git add

    . ADD ALL THE THINGS!!1
  32. Commit our snapshot to the repository $ git commit -m

    “Initial Commit” COMMIT
  33. Congratulations! You’ve successfully created a Git repository and committed a

    permanent snapshot of your files! YOU ROCK!
  34. FASTEN YOUR SEATBELTS

  35. VIEWING COMMITS $ git log

  36. Roll back to previous commits $ git checkout db210f ROLLBACK

  37. 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:
  38. 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!
  39. OH NOES! A WILD MERGE CONFLICT APPEARS!!

  40. None
  41. None
  42. None
  43. None
  44. Customized Log Output: https://gist.github.com/3453149

  45. WHEW! DISASTER AVERTED!

  46. WORDPRESS & VERSION CONTROL Now with multiple environments!

  47. DEPLOY WORKFLOW Development Environment Set up remotes to live server

    Deploy changes!
  48. Special file: .gitignore Goes in the root of your repo

    Add filenames or directories that Git should ignore .GITIGNORE
  49. .GITIGNORE wp-config.local.php .DS_Store/Thumbs.db .htaccess wp-content/uploads/ wp-content/cache/ Optional - ignore user

    uploads Optional - ignore live cache
  50. 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/
  51. Test for If it exists, use it If not, use

    Production DB info WP-CONFIG.PHP wp-config.local.php
  52. WP-CONFIG.PHP

  53. 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’
  54. 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
  55. $ 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
  56. 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
  57. HOOKS Located in .git/hooks applypatch-msg commit-msg post-update pre-applypatch pre-commit pre-rebase

    prepare-commit-msg update
  58. POST-UPDATE HOOK Fires after receiving a push from a remote

    /git-hub/hooks/post-update
  59. /domains/site.com/html PRIME $ git init $ git remote add hub

    /domains/site.com/git-hub Secure the .git directory with .htaccess!
  60. $ git remote add hub ssh://login@host.com/home/domains/site.com/git-hub DEVELOPMENT ENVIRONMENT Add a

    remote from DEV to HUB
  61. DEPLOY! $ git add . $ git commit -am “Updated

    header to include nav links” $ git push hub master
  62. DEPLOY SUCCESSFUL!

  63. 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
  64. CAUTION! If you did NOT put the wp-content/uploads folder in

    .gitignore, you will have to manually commit changes frequently
  65. PRETTY MUCH THIS Version control is amazing! It will improve

    your life! Using the basics is simple! Google is your friend!
  66. aaronjholbrook.com/?p=310 Slides @aaronjholbrook a7web.com aaron@a7web.com #wpgit #wcchi