git for wordpress developers
DESCRIPTION
Presentation given at WordCamp Denver on 10-13-2012TRANSCRIPT
.Git Wah?Everyting you wanted to know about .Git but were
afraid to ask?
Mike Van Winkle
• Developer @ WP Engine
• Freelance WordPress Developer for 3 years
• Second career
• Santa Rosa, CA
Utopia
• I write perfect code.
• I upload perfect code to website.
• Nobody touches my perfect code without asking me first.
• Rinse and Repeat.
Reality
• Other developers on a project
• I do stupid things
• Clients sometimes think they can code
• Shit happens
Version Control
• The Problem: How do we maintain stability and continuity in our websites/applications?
• The Answer: We save versions.
Realistic Workflow
http://nvie.com/posts/a-successful-git-branching-model/
Realistic Workflow
http://nvie.com/posts/a-successful-git-branching-model/
Version Control
• As much about transitioning a website between states as it is recording changes.
• Deployment is quicker and safer.
• Changes can be easily “rolled” back.
• A google example
Subversion or .Git
• SVN solves the problem by saving a “revision” with each change committed. Developers then can update code to a specific #
• Git Solves the problem by tracking the differences between commits
Subversion or .Git
• .Git is a “distributed” model with less server overhead and better performance
• .Git makes complex workflows much easier to manage
• Github.com is a great community of projects and developers sharing code.
• Little functions that make life easy (examples later)
Getting Started:What you need
• A command line tool like iTerm or Putty
• RSA Key Pair: https://help.github.com/articles/generating-ssh-keys
• Some Code
Getting Started: Set up a repo
Getting Started: Set up a repo
Getting Started:Then What?
$ git init
[create a .gitignore file ... touch .gitignore ]
$ git add . --all OR $ git add wp-content
$ git add remote origin [email protected]:mikevanwinkle/My-WP-Site.git
git commit -am “initial commit”
git push origin master
What to ignore?• Large Files
• Local Files
• custom .htaccess files
• custom wp-config.php
• WP Core
• Folders containing .svn info
• Historic Files
What to ignore?*~.svn.cvs.git.listing*.bak*.swp
cache.cachetemptmp*.tmpimagecache*uploads**_backupwp-config-sample.phpwp-content/w3tc*
wp-content/w3-*
wp-content/upgrade/*wp-content/uploadswp-content/blogs.dir/*/*pclzip-*log.txtdebug.loggallery/*
wp-content/gallery/*wp-content/album/*wp-content/plugins/plugins
.htaccess ? wp-config.php ?
Deployment
On your webhost, you’ll need ssh access or you will need a tool that can deploy via FTP ( Beanstalk ? )
$ git clone [email protected]:mikevanwinkle/My-WP-Site.git
$ git pull origin master
Development: Example[on your local]
$ git branch dev
$ git checkout dev
[make some changes]
$ git commit -am “Making my dev changes”
$ git push origin dev [pushes the new branch up]
[on production site]
$ git pull origin dev
$ git checkout dev
Development: Example[on your local]
$ git branch feature-1
$ git checkout feature-1
[make some changes]
$ git commit -am “Making my dev changes”
$ git push origin feature-1 [pushes the new branch up]
$ git checkout master
$ git merge feature-1
$ git commit -am “merge feature-1 with master”
$ git push origin master
Realistic Workflow
Realistic Workflow
Cool Stuff: Hooks• applypatch-msg
• post-commit
• post-update
• pre-commit
• update
• commit-msg
• post-receive
• pre-applypatch
• pre-rebase
Cool Stuff: Stash• applypatch-msg
• post-commit
• post-update
• pre-commit
• update
• commit-msg
• post-receive
• pre-applypatch
• pre-rebase
Cool Stuff: Stash
$ git stash save “Temp 2”
$ git stash list
$ git stash apply <STASH ID>
http://git-scm.com/book/en/Git-Tools-Stashing
Cool Stuff: Reset
$ git reset --hard HEAD
Cool Stuff: Reset
$ git reset --hard HEAD
Cool Stuff: Archive
$ git archive HEAD | gzip > /tmp/website.tar.gz
Resources
http://rkulla.blogspot.com/2011/08/some-points-on-git-vs-subversion.html
http://ryanflorence.com/deploying-websites-with-a-tiny-git-hook/
http://git.wpengine.com/faq/
https://help.github.com/
http://git-scm.com/docs/git-merge