Developing with WordPress and Git

117
Developing with WordPress and Git Rob Miller • @robmil Big Fish Design 1 Friday, 23 November 12

description

A talk given at the Wordpress London meetup about version control, Git, and how to most effectively use Git with WordPress.

Transcript of Developing with WordPress and Git

Page 1: Developing with WordPress and Git

Developing with WordPress and Git

Rob Miller • @robmilBig Fish Design

1Friday, 23 November 12

Page 2: Developing with WordPress and Git

An introduction

2Friday, 23 November 12

Page 3: Developing with WordPress and Git

“Git”? Huh?What’s that?

3Friday, 23 November 12

Page 4: Developing with WordPress and Git

“Git”? Huh?What’s that?

• A distributed version control system

3Friday, 23 November 12

Page 5: Developing with WordPress and Git

“Git”? Huh?What’s that?

• A distributed version control system

• Free

3Friday, 23 November 12

Page 6: Developing with WordPress and Git

“Git”? Huh?What’s that?

• A distributed version control system

• Free

• Open source

3Friday, 23 November 12

Page 7: Developing with WordPress and Git

“Git”? Huh?What’s that?

• A distributed version control system

• Free

• Open source

• Popular

3Friday, 23 November 12

Page 8: Developing with WordPress and Git

A crash course in version control

4Friday, 23 November 12

Page 9: Developing with WordPress and Git

What isversion control?

5Friday, 23 November 12

Page 10: Developing with WordPress and Git

What isversion control?

• Track changes made to source code

5Friday, 23 November 12

Page 11: Developing with WordPress and Git

What isversion control?

• Track changes made to source code

• Who did what and when

5Friday, 23 November 12

Page 12: Developing with WordPress and Git

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

Page 13: Developing with WordPress and Git

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

Page 14: Developing with WordPress and Git

Why version control?

6Friday, 23 November 12

Page 15: Developing with WordPress and Git

Why version control?

• “I just deleted a file by mistake — can we get it back?”

6Friday, 23 November 12

Page 16: Developing with WordPress and Git

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

Page 17: Developing with WordPress and Git

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

Page 18: Developing with WordPress and Git

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

Page 19: Developing with WordPress and Git

Centralisedvs. distributed

7Friday, 23 November 12

Page 20: Developing with WordPress and Git

Centralisedversion control

8Friday, 23 November 12

Page 21: Developing with WordPress and Git

Centralisedversion control

• History stored in a central repository running on a server

8Friday, 23 November 12

Page 22: Developing with WordPress and Git

Centralisedversion control

• History stored in a central repository running on a server

• Everyone commits to and from this repository

8Friday, 23 November 12

Page 23: Developing with WordPress and Git

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

Page 24: Developing with WordPress and Git

Distributedversion control

9Friday, 23 November 12

Page 25: Developing with WordPress and Git

Distributedversion control

• No central server

9Friday, 23 November 12

Page 26: Developing with WordPress and Git

Distributedversion control

• No central server

• Every team member has a copy of the entire repository and its history

9Friday, 23 November 12

Page 27: Developing with WordPress and Git

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

Page 28: Developing with WordPress and Git

Advantages of DVCS

10Friday, 23 November 12

Page 29: Developing with WordPress and Git

Advantages of DVCS

• Redundancy

10Friday, 23 November 12

Page 30: Developing with WordPress and Git

Advantages of DVCS

• Redundancy

• Offline working

10Friday, 23 November 12

Page 31: Developing with WordPress and Git

Advantages of DVCS

• Redundancy

• Offline working

• Speed

10Friday, 23 November 12

Page 32: Developing with WordPress and Git

Git

11Friday, 23 November 12

Page 33: Developing with WordPress and Git

Git ≠ GitHub

12Friday, 23 November 12

Page 34: Developing with WordPress and Git

Terminology, part one

13Friday, 23 November 12

Page 35: Developing with WordPress and Git

Terminology, part one

•Commit

13Friday, 23 November 12

Page 36: Developing with WordPress and Git

Terminology, part one

•Commit

•Branch

13Friday, 23 November 12

Page 37: Developing with WordPress and Git

Terminology, part one

•Commit

•Branch

•Tag

13Friday, 23 November 12

Page 38: Developing with WordPress and Git

Terminology, part one

•Commit

•Branch

•Tag

•Diff

13Friday, 23 November 12

Page 39: Developing with WordPress and Git

Terminology, part one

•Commit

•Branch

•Tag

•Diff

•Commitish

13Friday, 23 November 12

Page 40: Developing with WordPress and Git

Terminology, part two

14Friday, 23 November 12

Page 41: Developing with WordPress and Git

Terminology, part two

• Pulling

14Friday, 23 November 12

Page 42: Developing with WordPress and Git

Terminology, part two

• Pulling

• Pushing

14Friday, 23 November 12

Page 43: Developing with WordPress and Git

Terminology, part two

• Pulling

• Pushing

• Cloning

14Friday, 23 November 12

Page 44: Developing with WordPress and Git

What’s in a Git commit?

15Friday, 23 November 12

Page 45: Developing with WordPress and Git

What’s in a Git commit?

15Friday, 23 November 12

Page 46: Developing with WordPress and Git

What’s in a Git commit?

15Friday, 23 November 12

Page 47: Developing with WordPress and Git

What’s in a Git commit?

15Friday, 23 November 12

Page 48: Developing with WordPress and Git

What’s in a Git commit?

15Friday, 23 November 12

Page 49: Developing with WordPress and Git

Branches

16Friday, 23 November 12

Page 50: Developing with WordPress and Git

Branches

• In Subversion, they’re basically useless

16Friday, 23 November 12

Page 51: Developing with WordPress and Git

Branches

• In Subversion, they’re basically useless

• In Git, they’re at the heart of almost everything

16Friday, 23 November 12

Page 52: Developing with WordPress and Git

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

Page 53: Developing with WordPress and Git

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

Page 54: Developing with WordPress and Git

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

Page 55: Developing with WordPress and Git

Special branch

17Friday, 23 November 12

Page 56: Developing with WordPress and Git

Special branch

• Git doesn’t force you to have any particular branches

17Friday, 23 November 12

Page 57: Developing with WordPress and Git

Special branch

• Git doesn’t force you to have any particular branches

• But by convention, master is your stable branch

17Friday, 23 November 12

Page 58: Developing with WordPress and Git

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

Page 59: Developing with WordPress and Git

Branch commands

18Friday, 23 November 12

Page 60: Developing with WordPress and Git

• git branch foo will create a branch called “foo”.

Branch commands

18Friday, 23 November 12

Page 61: Developing with WordPress and Git

• 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

Page 62: Developing with WordPress and Git

• 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

Page 63: Developing with WordPress and Git

Merging

19Friday, 23 November 12

Page 64: Developing with WordPress and Git

• 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

Page 65: Developing with WordPress and Git

When shouldyou branch?

20Friday, 23 November 12

Page 66: Developing with WordPress and Git

• For individual features

When shouldyou branch?

20Friday, 23 November 12

Page 67: Developing with WordPress and Git

• For individual features

• What does that mean, though?

When shouldyou branch?

20Friday, 23 November 12

Page 68: Developing with WordPress and Git

• For individual features

• What does that mean, though?

• Generally: anything that might be put live independently

When shouldyou branch?

20Friday, 23 November 12

Page 69: Developing with WordPress and Git

Setting up a repository

21Friday, 23 November 12

Page 70: Developing with WordPress and Git

22Friday, 23 November 12

Page 71: Developing with WordPress and Git

$ git init

22Friday, 23 November 12

Page 72: Developing with WordPress and Git

Working with a team

23Friday, 23 November 12

Page 73: Developing with WordPress and Git

A typical team setup

24Friday, 23 November 12

Page 74: Developing with WordPress and Git

A typical team setup

You

24Friday, 23 November 12

Page 75: Developing with WordPress and Git

A typical team setup

The rest of the team

You

24Friday, 23 November 12

Page 76: Developing with WordPress and Git

A typical team setup

The rest of the team

Hub

You

24Friday, 23 November 12

Page 77: Developing with WordPress and Git

A typical team setup

The rest of the team

Hub

Staging

You

24Friday, 23 November 12

Page 78: Developing with WordPress and Git

A typical team setup

The rest of the team

Hub

Staging

ProductionYou

24Friday, 23 November 12

Page 79: Developing with WordPress and Git

Hooks

25Friday, 23 November 12

Page 80: Developing with WordPress and Git

26Friday, 23 November 12

Page 81: Developing with WordPress and Git

• Scripts that run after certain events — just like actions in WordPress

26Friday, 23 November 12

Page 82: Developing with WordPress and Git

• Scripts that run after certain events — just like actions in WordPress

• Potential uses:

26Friday, 23 November 12

Page 83: Developing with WordPress and Git

• 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

Page 84: Developing with WordPress and Git

• 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

Page 85: Developing with WordPress and Git

• 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

Page 86: Developing with WordPress and Git

Git and WordPress

27Friday, 23 November 12

Page 87: Developing with WordPress and Git

Things to exclude

28Friday, 23 November 12

Page 88: Developing with WordPress and Git

Things to exclude

• wp-config.php

28Friday, 23 November 12

Page 89: Developing with WordPress and Git

Things to exclude

• wp-config.php

• wp-uploads/* (or perhaps not…)

28Friday, 23 November 12

Page 90: Developing with WordPress and Git

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

Page 91: Developing with WordPress and Git

Image uploads

29Friday, 23 November 12

Page 92: Developing with WordPress and Git

Image uploads

• Image uploads inevitably happen on live

29Friday, 23 November 12

Page 93: Developing with WordPress and Git

Image uploads

• Image uploads inevitably happen on live

• Are they content (so should be excluded from Git)?

29Friday, 23 November 12

Page 94: Developing with WordPress and Git

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

Page 95: Developing with WordPress and Git

Potential solutions

30Friday, 23 November 12

Page 96: Developing with WordPress and Git

Potential solutions

• Ignore them — don’t have them in Git at all

30Friday, 23 November 12

Page 97: Developing with WordPress and Git

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

Page 98: Developing with WordPress and Git

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

Page 99: Developing with WordPress and Git

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

Page 100: Developing with WordPress and Git

Plugin/core upgrades

31Friday, 23 November 12

Page 101: Developing with WordPress and Git

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

Page 102: Developing with WordPress and Git

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

Page 103: Developing with WordPress and Git

Solutions

32Friday, 23 November 12

Page 104: Developing with WordPress and Git

Solutions

• Disable upgrades/plugin installs on your live sites, do upgrades locally, then deploy to live

32Friday, 23 November 12

Page 105: Developing with WordPress and Git

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

Page 106: Developing with WordPress and Git

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

Page 108: Developing with WordPress and Git

Git GUIs

34Friday, 23 November 12

Page 109: Developing with WordPress and Git

Git GUIs

• Use the command line first!

34Friday, 23 November 12

Page 110: Developing with WordPress and Git

Git GUIs

• Use the command line first!

• But on Windows: Tortoise Git

34Friday, 23 November 12

Page 111: Developing with WordPress and Git

Git GUIs

• Use the command line first!

• But on Windows: Tortoise Git

• On OS X: Tower, GitBox, Gitti

34Friday, 23 November 12

Page 112: Developing with WordPress and Git

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

Page 113: Developing with WordPress and Git

And finally…

35Friday, 23 November 12

Page 114: Developing with WordPress and Git

And finally…

35Friday, 23 November 12

Page 115: Developing with WordPress and Git

And finally…

• Jeff’s leaving! :(

35Friday, 23 November 12

Page 116: Developing with WordPress and Git

And finally…

• Jeff’s leaving! :(

• We’re hiring! :)

35Friday, 23 November 12

Page 117: Developing with WordPress and Git

And finally…

• Jeff’s leaving! :(

• We’re hiring! :)

• Apply online: http://bit.ly/SZJJ8v

or email: [email protected]

35Friday, 23 November 12