Using Git with WordPress - Presented by Nigel Rodgers.

Post on 06-Jan-2017

92 views 1 download

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

WordPress Development With Git

Imagine You’ve been hired to build a web app

Maybe you start with basic WordPress Install

You work on the project for a few days

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

you delete your code

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

but you’ve deleted it.

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

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

Collaboration can be challenging

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

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)

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.

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)

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

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.

Create child theme folder wc_twentyfourteen

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

repository

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

folder

Git Status

Git add

Git commit

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

Customized the footer and commit

Git log

Git Checkout

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

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

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

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

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

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

More about VersionPress

www.versionpress.com

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: rodgersnigel@gmail.com

Blog: mwanavhu.wordpress.com