3. “Git”? Huh?
What’s that?
Friday, 23 November 12 3
4. “Git”? Huh?
What’s that?
• A distributed version control system
Friday, 23 November 12 3
5. “Git”? Huh?
What’s that?
• A distributed version control system
• Free
Friday, 23 November 12 3
6. “Git”? Huh?
What’s that?
• A distributed version control system
• Free
• Open source
Friday, 23 November 12 3
7. “Git”? Huh?
What’s that?
• A distributed version control system
• Free
• Open source
• Popular
Friday, 23 November 12 3
8. A crash course in
version control
Friday, 23 November 12 4
9. What is
version control?
Friday, 23 November 12 5
10. What is
version control?
• Track changes made to source code
Friday, 23 November 12 5
11. What is
version control?
• Track changes made to source code
• Who did what and when
Friday, 23 November 12 5
12. What is
version control?
• Track changes made to source code
• Who did what and when
• When things break, revert to the point
when it last worked
Friday, 23 November 12 5
13. What is
version 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…)
Friday, 23 November 12 5
15. Why version control?
• “I just deleted a file by mistake — can we get
it back?”
Friday, 23 November 12 6
16. 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?”
Friday, 23 November 12 6
17. 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?”
Friday, 23 November 12 6
18. 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?”
Friday, 23 November 12 6
19. Centralised
vs. distributed
Friday, 23 November 12 7
20. Centralised
version control
Friday, 23 November 12 8
21. Centralised
version control
• History stored in a central repository
running on a server
Friday, 23 November 12 8
22. Centralised
version control
• History stored in a central repository
running on a server
• Everyone commits to and from this
repository
Friday, 23 November 12 8
23. Centralised
version control
• History stored in a central repository
running on a server
• Everyone commits to and from this
repository
• Examples: CVS, Subversion (SVN),
Perforce, ClearCase
Friday, 23 November 12 8
24. Distributed
version control
Friday, 23 November 12 9
25. Distributed
version control
• No central server
Friday, 23 November 12 9
26. Distributed
version control
• No central server
• Every team member has a copy of the
entire repository and its history
Friday, 23 November 12 9
27. Distributed
version 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
Friday, 23 November 12 9
50. Branches
• In Subversion, they’re basically useless
Friday, 23 November 12 16
51. Branches
• In Subversion, they’re basically useless
• In Git, they’re at the heart of almost
everything
Friday, 23 November 12 16
52. 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
Friday, 23 November 12 16
53. 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
Friday, 23 November 12 16
54. 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
Friday, 23 November 12 16
56. Special branch
• Git doesn’t force you to have any
particular branches
Friday, 23 November 12 17
57. Special branch
• Git doesn’t force you to have any
particular branches
• But by convention, master is your
stable branch
Friday, 23 November 12 17
58. 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
Friday, 23 November 12 17
60. Branch commands
• git branch foo will create a branch
called “foo”.
Friday, 23 November 12 18
61. Branch commands
• git branch foo will create a branch
called “foo”.
• git checkout bar will switch to the
branch called “bar”
Friday, 23 November 12 18
62. Branch commands
• 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
Friday, 23 November 12 18
64. Merging
• Once you’re done with a branch, you
can merge it into another:
$ git checkout master
$ git merge --no-ff foo
Friday, 23 November 12 19
65. When should
you branch?
Friday, 23 November 12 20
66. When should
you branch?
• For individual features
Friday, 23 November 12 20
67. When should
you branch?
• For individual features
• What does that mean, though?
Friday, 23 November 12 20
68. When should
you branch?
• For individual features
• What does that mean, though?
• Generally: anything that might be put
live independently
Friday, 23 November 12 20
69. Setting up
a repository
Friday, 23 November 12 21
81. • Scripts that run after certain events
— just like actions in WordPress
Friday, 23 November 12 26
82. • Scripts that run after certain events
— just like actions in WordPress
• Potential uses:
Friday, 23 November 12 26
83. • Scripts that run after certain events
— just like actions in WordPress
• Potential uses:
• Post a message in an IRC channel
when someone pushes
Friday, 23 November 12 26
84. • 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
Friday, 23 November 12 26
85. • 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
Friday, 23 November 12 26
89. Things to exclude
• wp-config.php
• wp-uploads/* (or perhaps not…)
Friday, 23 November 12 28
90. Things to exclude
• wp-config.php
• wp-uploads/* (or perhaps not…)
• Anything that might conceivably be
different on live vs. development
Friday, 23 November 12 28
92. Image uploads
• Image uploads inevitably happen on
live
Friday, 23 November 12 29
93. Image uploads
• Image uploads inevitably happen on
live
• Are they content (so should be
excluded from Git)?
Friday, 23 November 12 29
94. 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)?
Friday, 23 November 12 29
96. Potential solutions
• Ignore them — don’t have them in Git at all
Friday, 23 November 12 30
97. Potential solutions
• Ignore them — don’t have them in Git at all
• Periodically add them into Git from the live
server
Friday, 23 November 12 30
98. 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
Friday, 23 November 12 30
99. 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
Friday, 23 November 12 30
100. Plugin/core
upgrades
Friday, 23 November 12 31
101. Plugin/core
upgrades
• If they happen on live, you’ll end up
with untracked files/uncommitted
changes to your live files
Friday, 23 November 12 31
102. 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
Friday, 23 November 12 31
104. Solutions
• Disable upgrades/plugin installs on your live
sites, do upgrades locally, then deploy to live
Friday, 23 November 12 32
105. 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
Friday, 23 November 12 32
106. 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
Friday, 23 November 12 32
107. 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
Friday, 23 November 12 33
109. Git GUIs
• Use the command line first!
Friday, 23 November 12 34
110. Git GUIs
• Use the command line first!
• But on Windows: Tortoise Git
Friday, 23 November 12 34
111. Git GUIs
• Use the command line first!
• But on Windows: Tortoise Git
• On OS X: Tower, GitBox, Gitti
Friday, 23 November 12 34
112. Git GUIs
• Use the command line first!
• But on Windows: Tortoise Git
• On OS X: Tower, GitBox, Gitti
• On Linux: giggle, gitg, QGit
Friday, 23 November 12 34