WordPress & Version Control: A Workflow

  • View
    105

  • 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!

Text of WordPress & Version Control: A Workflow

  • 1. WordPress and Version Control A Workflow $ Aaron Holbrook A7 Web Design, Owneraaron@a7web.comMonday, June 11, 12

2. aaron@a7web.com @aaronjholbrooka7web.com #wcmke #wpgitMonday, June 11, 12 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. have you ever... Wanted to make your changes live with the push of a button? Hated dragging les into FTP and wished for a better way? Been editing via FTP, made a change, closed the editor and immediately realized you shouldnt have closed it? Lost code and didnt 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. 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. disclaimer!ma y vary) ileageYMMV (your m This workow is something that Ive rened to suit my needs, feel free to adjust it to suit yours #wcmke #wpgitMonday, June 11, 12 7. assumptions Youre aware of how important Version Control is, but have not fully integrated it into your workow 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 Youd like to have seamless, simple deployments #wcmke #wpgitMonday, June 11, 12 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. things youll need Terminal Git SSH #wcmke #wpgitMonday, June 11, 12 10. legend Whenever you see $ command here Everything after the $ is what you should type #wcmke #wpgitMonday, June 11, 12 11. A civilized tool for a civilized age - Si, stack overowMonday, June 11, 12 12. git 101 You can dene 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. .gitignore .DS_Store wp-cong.local.php .htaccessOptional - ignore user uploads wp-content/uploads/Optional - ignore live cache wp-content/cache/ #wcmke #wpgitMonday, June 11, 12 14. git 102 In your git repo, add all les $ git add . Commit! $ git commit -m Commit MessageSuccess! -m allows an inline commit m essage #wcmke #wpgitMonday, June 11, 12 15. DeployMonday, June 11, 12 16. this fileis twp-config.local.php he magic key 1. Dene local variables withoutcontaminating the server 2. Add a call to wp-config.php to check forthis le and load it if it exists Credit to Mark Jaquith who came up with this idea #wcmke #wpgit http://markjaquith.wordpress.com/2011/06/24/wordpress-local-dev-tips/Monday, June 11, 12 17. thisfile is twp-config.local.phphe m agickey #wcmke #wpgitMonday, June 11, 12 18. wp-config.php 1. Test for wp-config.local.php 2. If it doesnt exist, then use live serverconnection information #wcmke #wpgitMonday, June 11, 12 19. wp-config.php #wcmke #wpgitMonday, June 11, 12 20. ssh 101 1. $ ssh login@server.com 2. Enter password 3. success #wcmke #wpgitMonday, June 11, 12 21. HUB & PRIME On the server, we will create two repositoriesHUB will be the main collaboratorPRIME will be the live site repositoryMajor props to Joe Maller #wcmke #wpgit http://joemaller.com/990/a-web-focused-git-workflow/Monday, June 11, 12 22. hub HUB Create hub as a bare repositoryI generally put it right above the sites html root in a git-hub* folder /domains/site.com/html /domains/site.com/git-hub$ git init --bare* Not to be confused with the fantastic GitHub website #wcmke #wpgit https://github.com/Monday, June 11, 12 23. HUB hook Well want PRIME to auto-update when we push our changes up to H HUB So lets set up a hook! #wcmke #wpgitMonday, June 11, 12 24. HUB hook/git-hub/hooks/post-update #wcmke #wpgitMonday, June 11, 12 25. PRIME 1. Create as regular repo$ git init 2. Add remote to HUB$ git remote add hub /domains/site.com/git-hub #wcmke #wpgitMonday, June 11, 12 26. and finally Set up our local remote to HUB$ git remote add hub ssh://login@host.com/home/domains/site.com/git-hub Success! #wcmke #wpgitMonday, June 11, 12 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 Weve deployed!hooray! #wcmke #wpgitMonday, June 11, 12 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. 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. 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. a7web.com @aaronjholbrookaaron@a7web.com #wcmke #wpgitMonday, June 11, 12