developing with wordpress and git
DESCRIPTION
A talk given at the Wordpress London meetup about version control, Git, and how to most effectively use Git with WordPress.TRANSCRIPT
Developing with WordPress and Git
Rob Miller • @robmilBig Fish Design
1Friday, 23 November 12
An introduction
2Friday, 23 November 12
“Git”? Huh?What’s that?
3Friday, 23 November 12
“Git”? Huh?What’s that?
• A distributed version control system
3Friday, 23 November 12
“Git”? Huh?What’s that?
• A distributed version control system
• Free
3Friday, 23 November 12
“Git”? Huh?What’s that?
• A distributed version control system
• Free
• Open source
3Friday, 23 November 12
“Git”? Huh?What’s that?
• A distributed version control system
• Free
• Open source
• Popular
3Friday, 23 November 12
A crash course in version control
4Friday, 23 November 12
What isversion control?
5Friday, 23 November 12
What isversion control?
• Track changes made to source code
5Friday, 23 November 12
What isversion control?
• Track changes made to source code
• Who did what and when
5Friday, 23 November 12
What isversion control?
• Track changes made to source code
• Who did what and when
• When things break, revert to the point when it last worked
5Friday, 23 November 12
What isversion control?
• Track changes made to source code
• Who did what and when
• When things break, revert to the point when it last worked
• Like Time Machine for your website’s code (but not database/content…)
5Friday, 23 November 12
Why version control?
6Friday, 23 November 12
Why version control?
• “I just deleted a file by mistake — can we get it back?”
6Friday, 23 November 12
Why version control?
• “I just deleted a file by mistake — can we get it back?”
• “I need to know who made this change — can we find out?”
6Friday, 23 November 12
Why version control?
• “I just deleted a file by mistake — can we get it back?”
• “I need to know who made this change — can we find out?”
• “That feature just broke the site — can we revert it?”
6Friday, 23 November 12
Why version control?
• “I just deleted a file by mistake — can we get it back?”
• “I need to know who made this change — can we find out?”
• “That feature just broke the site — can we revert it?”
• “There’s a bug that didn’t use to exist. When was it introduced?”
6Friday, 23 November 12
Centralisedvs. distributed
7Friday, 23 November 12
Centralisedversion control
8Friday, 23 November 12
Centralisedversion control
• History stored in a central repository running on a server
8Friday, 23 November 12
Centralisedversion control
• History stored in a central repository running on a server
• Everyone commits to and from this repository
8Friday, 23 November 12
Centralisedversion control
• History stored in a central repository running on a server
• Everyone commits to and from this repository
• Examples: CVS, Subversion (SVN), Perforce, ClearCase
8Friday, 23 November 12
Distributedversion control
9Friday, 23 November 12
Distributedversion control
• No central server
9Friday, 23 November 12
Distributedversion control
• No central server
• Every team member has a copy of the entire repository and its history
9Friday, 23 November 12
Distributedversion control
• No central server
• Every team member has a copy of the entire repository and its history
• Git isn’t the only option — e.g. Mercurial
9Friday, 23 November 12
Advantages of DVCS
10Friday, 23 November 12
Advantages of DVCS
• Redundancy
10Friday, 23 November 12
Advantages of DVCS
• Redundancy
• Offline working
10Friday, 23 November 12
Advantages of DVCS
• Redundancy
• Offline working
• Speed
10Friday, 23 November 12
Git
11Friday, 23 November 12
Git ≠ GitHub
12Friday, 23 November 12
Terminology, part one
13Friday, 23 November 12
Terminology, part one
•Commit
13Friday, 23 November 12
Terminology, part one
•Commit
•Branch
13Friday, 23 November 12
Terminology, part one
•Commit
•Branch
•Tag
13Friday, 23 November 12
Terminology, part one
•Commit
•Branch
•Tag
•Diff
13Friday, 23 November 12
Terminology, part one
•Commit
•Branch
•Tag
•Diff
•Commitish
13Friday, 23 November 12
Terminology, part two
14Friday, 23 November 12
Terminology, part two
• Pulling
14Friday, 23 November 12
Terminology, part two
• Pulling
• Pushing
14Friday, 23 November 12
Terminology, part two
• Pulling
• Pushing
• Cloning
14Friday, 23 November 12
What’s in a Git commit?
15Friday, 23 November 12
What’s in a Git commit?
15Friday, 23 November 12
What’s in a Git commit?
15Friday, 23 November 12
What’s in a Git commit?
15Friday, 23 November 12
What’s in a Git commit?
15Friday, 23 November 12
Branches
16Friday, 23 November 12
Branches
• In Subversion, they’re basically useless
16Friday, 23 November 12
Branches
• In Subversion, they’re basically useless
• In Git, they’re at the heart of almost everything
16Friday, 23 November 12
Branches
• In Subversion, they’re basically useless
• In Git, they’re at the heart of almost everything
• Juggle as many different versions of your code as you like
16Friday, 23 November 12
Branches
• In Subversion, they’re basically useless
• In Git, they’re at the heart of almost everything
• Juggle as many different versions of your code as you like
• Keep all your features nice and separate
16Friday, 23 November 12
Branches
• In Subversion, they’re basically useless
• In Git, they’re at the heart of almost everything
• Juggle as many different versions of your code as you like
• Keep all your features nice and separate
• Merge painlessly once you’re done
16Friday, 23 November 12
Special branch
17Friday, 23 November 12
Special branch
• Git doesn’t force you to have any particular branches
17Friday, 23 November 12
Special branch
• Git doesn’t force you to have any particular branches
• But by convention, master is your stable branch
17Friday, 23 November 12
Special branch
• Git doesn’t force you to have any particular branches
• But by convention, master is your stable branch
• Branch from it; merge to it; your releases are taken from it
17Friday, 23 November 12
Branch commands
18Friday, 23 November 12
• git branch foo will create a branch called “foo”.
Branch commands
18Friday, 23 November 12
• git branch foo will create a branch called “foo”.
• git checkout bar will switch to the branch called “bar”
Branch commands
18Friday, 23 November 12
• git branch foo will create a branch called “foo”.
• git checkout bar will switch to the branch called “bar”
• git branch -d foo will delete a branch if you change your mind about it
Branch commands
18Friday, 23 November 12
Merging
19Friday, 23 November 12
• Once you’re done with a branch, you can merge it into another:
$ git checkout master$ git merge --no-ff foo
Merging
19Friday, 23 November 12
When shouldyou branch?
20Friday, 23 November 12
• For individual features
When shouldyou branch?
20Friday, 23 November 12
• For individual features
• What does that mean, though?
When shouldyou branch?
20Friday, 23 November 12
• For individual features
• What does that mean, though?
• Generally: anything that might be put live independently
When shouldyou branch?
20Friday, 23 November 12
Setting up a repository
21Friday, 23 November 12
22Friday, 23 November 12
$ git init
22Friday, 23 November 12
Working with a team
23Friday, 23 November 12
A typical team setup
24Friday, 23 November 12
A typical team setup
You
24Friday, 23 November 12
A typical team setup
The rest of the team
You
24Friday, 23 November 12
A typical team setup
The rest of the team
Hub
You
24Friday, 23 November 12
A typical team setup
The rest of the team
Hub
Staging
You
24Friday, 23 November 12
A typical team setup
The rest of the team
Hub
Staging
ProductionYou
24Friday, 23 November 12
Hooks
25Friday, 23 November 12
26Friday, 23 November 12
• Scripts that run after certain events — just like actions in WordPress
26Friday, 23 November 12
• Scripts that run after certain events — just like actions in WordPress
• Potential uses:
26Friday, 23 November 12
• Scripts that run after certain events — just like actions in WordPress
• Potential uses:
• Post a message in an IRC channel when someone pushes
26Friday, 23 November 12
• Scripts that run after certain events — just like actions in WordPress
• Potential uses:
• Post a message in an IRC channel when someone pushes
• Deploy to the live site when someone pushes on master
26Friday, 23 November 12
• Scripts that run after certain events — just like actions in WordPress
• Potential uses:
• Post a message in an IRC channel when someone pushes
• Deploy to the live site when someone pushes on master
• Run a syntax checker/strip whitespace/etc. before commits
26Friday, 23 November 12
Git and WordPress
27Friday, 23 November 12
Things to exclude
28Friday, 23 November 12
Things to exclude
• wp-config.php
28Friday, 23 November 12
Things to exclude
• wp-config.php
• wp-uploads/* (or perhaps not…)
28Friday, 23 November 12
Things to exclude
• wp-config.php
• wp-uploads/* (or perhaps not…)
• Anything that might conceivably be different on live vs. development
28Friday, 23 November 12
Image uploads
29Friday, 23 November 12
Image uploads
• Image uploads inevitably happen on live
29Friday, 23 November 12
Image uploads
• Image uploads inevitably happen on live
• Are they content (so should be excluded from Git)?
29Friday, 23 November 12
Image uploads
• Image uploads inevitably happen on live
• Are they content (so should be excluded from Git)?
• Or are they layout/template related (so should be included in Git)?
29Friday, 23 November 12
Potential solutions
30Friday, 23 November 12
Potential solutions
• Ignore them — don’t have them in Git at all
30Friday, 23 November 12
Potential solutions
• Ignore them — don’t have them in Git at all
• Periodically add them into Git from the live server
30Friday, 23 November 12
Potential solutions
• Ignore them — don’t have them in Git at all
• Periodically add them into Git from the live server
• Automate the adding of them e.g. with a WordPress hook
30Friday, 23 November 12
Potential solutions
• Ignore them — don’t have them in Git at all
• Periodically add them into Git from the live server
• Automate the adding of them e.g. with a WordPress hook
• Which solution depends on the nature of your images
30Friday, 23 November 12
Plugin/core upgrades
31Friday, 23 November 12
Plugin/core upgrades
• If they happen on live, you’ll end up with untracked files/uncommitted changes to your live files
31Friday, 23 November 12
Plugin/core upgrades
• If they happen on live, you’ll end up with untracked files/uncommitted changes to your live files
• Doing them on live is insane regardless, so it makes double sense to stop doing it
31Friday, 23 November 12
Solutions
32Friday, 23 November 12
Solutions
• Disable upgrades/plugin installs on your live sites, do upgrades locally, then deploy to live
32Friday, 23 November 12
Solutions
• Disable upgrades/plugin installs on your live sites, do upgrades locally, then deploy to live
• Remove install_plugins, install_themes, update_plugins, update_themes, update_core capabilities from your users on live
32Friday, 23 November 12
Solutions
• Disable upgrades/plugin installs on your live sites, do upgrades locally, then deploy to live
• Remove install_plugins, install_themes, update_plugins, update_themes, update_core capabilities from your users on live
• define('DISALLOW_FILE_EDIT', true); in your live wp-config.php
32Friday, 23 November 12
Useful resources
• “Think Like a Git”: http://think-like-a-git.net/
• GitRef: http://gitref.org/
• ProGit: http://git-scm.com/book
• Useful Git tips: http://mislav.uniqpath.com/2010/07/git-tips/
• “So, I’ve tried Git” by Ozh http://planetozh.com/blog/2012/11/so-ive-tried-git-and-its/
• Migrating an SVN repo to Git: http://john.albin.net/git/convert-subversion-to-git
33Friday, 23 November 12
Git GUIs
34Friday, 23 November 12
Git GUIs
• Use the command line first!
34Friday, 23 November 12
Git GUIs
• Use the command line first!
• But on Windows: Tortoise Git
34Friday, 23 November 12
Git GUIs
• Use the command line first!
• But on Windows: Tortoise Git
• On OS X: Tower, GitBox, Gitti
34Friday, 23 November 12
Git GUIs
• Use the command line first!
• But on Windows: Tortoise Git
• On OS X: Tower, GitBox, Gitti
• On Linux: giggle, gitg, QGit
34Friday, 23 November 12
And finally…
35Friday, 23 November 12
And finally…
35Friday, 23 November 12
And finally…
• Jeff’s leaving! :(
35Friday, 23 November 12
And finally…
• Jeff’s leaving! :(
• We’re hiring! :)
35Friday, 23 November 12
And finally…
• Jeff’s leaving! :(
• We’re hiring! :)
• Apply online: http://bit.ly/SZJJ8v
or email: [email protected]
35Friday, 23 November 12