Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

WordPress & Version Control: A Workflow


Published on

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!

Published in: Technology

WordPress & Version Control: A Workflow

  1. 1. WordPress  and   Version  Control A Workflow $ Aaron Holbrook A7 Web Design, Owner aaron@a7web.comMonday, June 11, 12
  2. 2. @aaronjholbrook #wcmke #wpgitMonday, June 11, 12
  3. 3. overview Background Disclaimer Assumptions Local Development Version Control (Git) Using WordPress & Git together Deployment Some demos Ask questions! #wcmke #wpgitMonday, June 11, 12
  4. 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 #wpgitMonday, June 11, 12
  5. 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 #wpgitMonday, June 11, 12
  6. 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 #wpgitMonday, June 11, 12
  7. 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 #wpgitMonday, June 11, 12
  8. 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 #wpgitMonday, June 11, 12
  9. 9. things you’ll need Terminal Git SSH #wcmke #wpgitMonday, June 11, 12
  10. 10. legend Whenever you see $ command here Everything after the $ is what you should type #wcmke #wpgitMonday, June 11, 12
  11. 11. “A civilized tool for a civilized age” - Si, stack overflowMonday, June 11, 12
  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 #wpgitMonday, June 11, 12
  13. 13. .gitignore .DS_Store wp-config.local.php .htaccess Optional - ignore user uploads wp-content/uploads/ Optional - ignore live cache wp-content/cache/ #wcmke #wpgitMonday, June 11, 12
  14. 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 #wpgitMonday, June 11, 12
  15. 15. DeployMonday, June 11, 12
  16. 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, June 11, 12
  17. 17. this file is t wp-config.local.php he m agic key #wcmke #wpgitMonday, June 11, 12
  18. 18. wp-config.php 1. Test for wp-config.local.php 2. If it doesn’t exist, then use live server connection information #wcmke #wpgitMonday, June 11, 12
  19. 19. wp-config.php #wcmke #wpgitMonday, June 11, 12
  20. 20. ssh 101 1. $ ssh 2. Enter password 3. success #wcmke #wpgitMonday, June 11, 12
  21. 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, June 11, 12
  22. 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/ /domains/ $ git init --bare * Not to be confused with the fantastic GitHub website #wcmke #wpgit, June 11, 12
  23. 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 #wpgitMonday, June 11, 12
  24. 24. HUB hook /git-hub/hooks/post-update #wcmke #wpgitMonday, June 11, 12
  25. 25. PRIME 1. Create as regular repo $ git init 2. Add remote to HUB $ git remote add hub /domains/ #wcmke #wpgitMonday, June 11, 12
  26. 26. and finally Set up our local remote to HUB $ git remote add hub ssh:// Success! #wcmke #wpgitMonday, June 11, 12
  27. 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 #wpgitMonday, June 11, 12
  28. 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 #wpgitMonday, June 11, 12
  29. 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 #wpgitMonday, June 11, 12
  30. 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 #wpgitMonday, June 11, 12
  31. 31. @aaronjholbrook #wcmke #wpgitMonday, June 11, 12