Using Git with WordPress - Presented by Nigel Rodgers.

31
WordPress Development With Git

Transcript of Using Git with WordPress - Presented by Nigel Rodgers.

Page 1: Using Git with WordPress - Presented by Nigel Rodgers.

WordPress Development With Git

Page 2: Using Git with WordPress - Presented by Nigel Rodgers.

Imagine You’ve been hired to build a web app

Maybe you start with basic WordPress Install

Page 3: Using Git with WordPress - Presented by Nigel Rodgers.

You work on the project for a few days

Page 4: Using Git with WordPress - Presented by Nigel Rodgers.

You Show the client a really great feature but she doesn’t like it so

you delete your code

Page 5: Using Git with WordPress - Presented by Nigel Rodgers.

A few days later your client suddenly loves the great feature,

but you’ve deleted it.

Page 6: Using Git with WordPress - Presented by Nigel Rodgers.

How do you manage your project files?

You may use a naming convention like:

Prototype 1

Prototype 2

Added Great Feature

Prototype 3

You may add a comment to the end of the file name to remember what edit it contains

Deleted Great Feature

Great Feature Again

Page 7: Using Git with WordPress - Presented by Nigel Rodgers.

In A project you’ll deal with multiple files with different versions that could go up to the thousands

Page 8: Using Git with WordPress - Presented by Nigel Rodgers.

Collaboration can be challenging

Page 9: Using Git with WordPress - Presented by Nigel Rodgers.

Version Control

○ Version control, revision control or source control○ any kind of practice that tracks and provides control

over changes to source code (Wikipedia)○ All software projects have some form of version

control○ Version Control Systems usually run as stand alone

applications○ Some examples are CVS, Subversion (SVN),

Mercurial and Git

Page 10: Using Git with WordPress - Presented by Nigel Rodgers.

Git (and VCS in general)

●Share code easily●Track changes ( and undo or redo them

easily)●Collaborate easily●Clearly communicate what changes have

been made●Improve workflow (easier to plan and execute

tasks)

Page 11: Using Git with WordPress - Presented by Nigel Rodgers.

How it works

●Git maintains a repository: A collection of project files with special information such as what changes occurred, a description of each change, and who made the change.

●Git does not automatically track changes, it has to be explicitly told when a version is finished, when that happens it’s called a commit.

Page 12: Using Git with WordPress - Presented by Nigel Rodgers.

The Repository

●Commits are stored as hidden files in the repository so that your project looks like it would without a VCS.

●Git provides a set of tools to manage the repository

●Git is accessed through the console/terminal (there are GUI tools but the terminal is the most powerful method)

Page 13: Using Git with WordPress - Presented by Nigel Rodgers.

Common Commands in Git●Init - initialize repository●commit - move changes to the repository●checkout - Retrieve a version of the project●branch - A separate version from the main

version of a project●master - The main version●merge - combine all the changes of two

branches into one.●log - a summary of the commits performed●status - the current state of the repository

showing tracked/untracked files, and changes since last commit

Page 14: Using Git with WordPress - Presented by Nigel Rodgers.

Working with Git in WordPress

There are many different workflows for using Git with WordPress, each with its strengths and weaknesses. For demonstration sake I will show how to track the development of a child theme with Git.

The demonstration may not follow WordPress best practices. The goal is to demonstrate Git as simply as possible.

Page 15: Using Git with WordPress - Presented by Nigel Rodgers.

Create child theme folder wc_twentyfourteen

Page 16: Using Git with WordPress - Presented by Nigel Rodgers.

In the console, inside the child theme folder, initialize the git

repository

Page 17: Using Git with WordPress - Presented by Nigel Rodgers.

Create functions.php, style.css and screenshot.png in the child theme

folder

Page 18: Using Git with WordPress - Presented by Nigel Rodgers.

Git Status

Page 19: Using Git with WordPress - Presented by Nigel Rodgers.

Git add

Page 20: Using Git with WordPress - Presented by Nigel Rodgers.

Git commit

Page 21: Using Git with WordPress - Presented by Nigel Rodgers.

Add footer.php file to the child theme folder and commit

Page 22: Using Git with WordPress - Presented by Nigel Rodgers.

Customized the footer and commit

Page 23: Using Git with WordPress - Presented by Nigel Rodgers.

Git log

Page 24: Using Git with WordPress - Presented by Nigel Rodgers.

Git Checkout

Checkout between the master and previous commit and observe how the site changes on reload

Page 25: Using Git with WordPress - Presented by Nigel Rodgers.

Wow! A lot of work for just a footer!

●The exercise shows the basic concept of git, in practice you won’t have to commit every little change.

●The git workflow you use will depend on personal or organisational preference

●As you get used to the commands and use git consistently it will become a powerful tool

●The demo did not even go into the powerful concept of branches

Page 26: Using Git with WordPress - Presented by Nigel Rodgers.

Why Use Git?

●Easier sharing (Github and Bitbucket)●Better workflow●Easier colaboration●Getting a job (Any company with a clue uses

come kind of version control.)

NB git is not a backup tool

Page 27: Using Git with WordPress - Presented by Nigel Rodgers.

Learn More

●Git offical: www.git-scm.com●Github: www.gitub.com●Bitbucket: www.bitbucket.org●Muzinda hub & teamtreehouse:

www.teamtreehouse.com●Google●WordPress meetups

Page 28: Using Git with WordPress - Presented by Nigel Rodgers.

VersionPress●Git is awesome for WordPress except you

can’t sync the database●VersionPress is a plugin that aims to resolve

this issue●VersionPress was meant to be for people who

aren’t interested in the technical side of git, however it is still challenging to install and use

Page 29: Using Git with WordPress - Presented by Nigel Rodgers.

What VersionPress can do

●Automatically track any changes on WordPress e.g. a post update, or plugin installed/updated

●Undo any actions like the above mentioned●Merge two databases. So you can sync your

production site with your development site.●Most of what git can do

Page 30: Using Git with WordPress - Presented by Nigel Rodgers.

More about VersionPress

www.versionpress.com

Page 31: Using Git with WordPress - Presented by Nigel Rodgers.

Thank You●You made it to the end of my boring

presentation!●Harare WordCamp team●Thanks to the sponsors●Keep cultivating the culture of sharing!

Nigel Rodgers: [email protected]

Blog: mwanavhu.wordpress.com