Tutorial Create a repository. Change a file. Add changes. Commit changes. View log. Repeat w/ Source Tree
Introduction to git & WordPress
Who am I?
● Owner & Director @ QC Creative
● PHP/MySQL Developer since 2004
● Front-end Specialist since 2007
● Amateur Photographer
● Lifelong Learner...
Why should you listen to me?
● Built custom PHP applications for clients
like Magic Hat & UVM
● Since 2010, have used WordPress for >90%
● Host & manage over 60 WordPress sites
How do we deploy now?
● “Cowboy Coding”
● FTP/SFTP/SCP with a local development
environment or staging server
● FTP/SFTP/SCP with local development AND
a staging server
Have you ever wondered...
● Did I edit that CSS file on my local copy or
on the FTP server?
● If I upload this, will it break anything?
● What if my client/boss wants me to undo all
of these changes?
We should be able to answer...
● Who changed this file?
● What did this file look like before?
● Where has this file been uploaded?
● When was this file changed?
● Why was this file changed?
Version Control to the Rescue!
● tracks changes to files, as well as variations
or “branches” of an entire project
● allows us to move through a history of
snapshots of our project
● allows us to share our work with others
git vs. SVN
● SVN is centralized.
● git is decentralized.
● git is often used with a centralized
SVN is centralized
● Complete project history is stored on a
● Individual developers “check out” the latest
versions of files in order to work on them.
● Branches are complete copies of the
project, stored in a separate folder.
git is distributed
● Every git repository contains a complete
history of the entire project.
● Any git repository can act as a “remote” for
any other git repository.
● Branches are cheap — they are just
In practice, git is centralized too...
● git doesn’t care, but for the humans, it is usually best
to declare a canonical central repository.
● Usually you’ll use a hosted service like github or
bitbucket for this, but it is also possible to host
● Teams may still share work amongst themselves before
“pushing” to the central repository.
Using git with subteams and a central repository
WordPress core development
● WordPress core development still uses SVN
● It is possible to use git for core
development, and convert your patches to
● Working directory
● Staging area
Using Branches Best
● With git, branches are your friends.
● Branch early, branch often.
● Learn how interactively:http://pcottle.github.io/learnGitBranching/
For sole developers
● Designate a branch as your “clean” branch — usually
● Create a new branch for each new feature or story.
● As a feature is completed and tested, merge its branch
into your clean branch, then deploy.
● Optionally maintain designated branches for each
server, to track what has been deployed.
● ONLY merge changes into server branches after you
have deployed the changes.
● Remote repositories can be anywhere.
● Usually, access is via SSH with private keys
for passwordless interactions.
● Sometimes the live site is a git repository.
We don’t want to track everything
● .gitignore is a plaintext file that tells git
which files and folders to ignore
● Create one for every repository
● Essential for using git with WordPress
● What to ignore:
o local config files
o self-contained external libraries
Using git with WordPress
● What do I track in git?
o My custom theme?
o My entire wp-content folder?
o My entire public folder?
o My entire project folder?
● Where do I keep my repositories?
Keep it anywhere.
2011: Mark Jaquith’s WP Skeleton
● Mark Jaquith is one of the lead WP Core
● Mark really doesn’t want you to cowboy
● He made WP-Skeleton, which is a starter git
repository for WordPress project.
● WordPress core files are kept in a
subdirectory, tracked as a git submodule.
● wp-config.php is modified to allow local
● Everything is awesome…
● git submodules are a major PITA.
● Submodules are not designed for
● Local config options could be more robust
and allow for multiple environments.
We need Dependency Management
● Wouldn’t it be great if we could keep one
list of all of the external plugins, themes,
and libraries required by our site, and have
it always kept up to date?
● Composer can do that for you.
● Installs, tracks and manages PHP libraries.
● WordPress is a PHP library
● WordPress plugins are PHP libraries
● WordPress themes are PHP libraries
● Most WordPress-directory plugins are
available for Composer through
Roots.io & Bedrock
● Bedrock is an open source WordPress
● It has everything you need to start using
composer and git with your WordPress
● Available at:
Thank you to Gregg Bense for organizing this
Thank you to the Fletcher Free Library for
hosting this event
Source Tree (http://www.sourcetreeapp.com/)
git-scm book (http://git-scm.com)
https://help.github.com/articles/generating-ssh-keys (The best info on SSH keys and how to use them with git)
http://www.slideshare.net/terrywang/git-101-tutorial-presentation (700-slide presentation — very
clear)http://pcottle.github.io/learnGitBranching/ (Interactive tutorial)