How to deploy wordpress themes with git

by aurooba ahmed

About me

  • Co-Founder of a dev/design studio Wanderoak
     
  • I learned Git out of necessity
     
  • I use Git almost everyday

you have heard of git

you actively use git

raise your hand if..

What is git?

  • a fast version control system
     
  • free and open source
     
  • used to host files on popular platform GitHub

What is version control

  • a way to record changes made to file(s) so you can recall them later
     
  • allows you to collaborate and share without overwriting changes
     
  • serves as an additional easy to read record of development

basic git workflow

  • you make changes to your file(s)
     
  • you choose what changes you want to add
     
  • you commit those changes and store them permanently in your repository
     
  • (optional-but-should-be-required) you send all changes in your local repository to a backup or central repository available in the cloud, every once in a while

basic git vocabulary

  • repository - a data structure that stores information about your project or set of files
     
  • bare repository - a storage facility where you store information but can't change or edit it (excellent for just sharing)
     
  • commit - a saved version of the project with certain new changes deemed 'safe'
     
  • remote - a bookmark to a connected repository you send information to
     
  • push - transferring commits to a connected repository (using a remote)

why you should use version control

  • easy to undo changes
     
  • easy to see what's different
     
  • really great for teams working on projects together

having an online staging environment

  • staging environment - an online 'clone' of your live site
     
  • share your work before it goes live (with your team and your clients)
     
  • double check everything works well on your live server

when you should deploy themes with git

  • when you are serving changes to a staging environment to test your work
     
  • be 110% confident everything works before sending any changes to your live site

how to deploy themes with git (finally)

this is not a step by step tutorial, you can view that at https://aurooba.com/wordcamp16.html

deployment workflow

  • commit changes to your local repository
     
  • push all changes to a bare repository on your server (server must have git installed)
     
  • see changes on staging site immediately!

Step 1:

initialize local repository

git init

Step 2:

create bare repository

  • ensure your server has git installed and then log into your server (on the command line)
  • never used the command line? Here's a quick tutorial
# set up your information on the server if you haven't 
# already
git config --global user.name "Aurooba Ahmed"
git config --global user.email typeyour@email.com

# create a directory that will house all your bare repos
mkdir theme-gitrepos
cd theme-gitrepos
# create directory to hold bare repo for theme called Mint
mkdir mint-repo 
# create bare repository
cd mint-repo
git init --bare

STEP 3:

Send changes to theme folder

  • we want all changes to be reflected in wp-content/your-theme
  • git hooks - custom scripts that fire when specific actions occur
  • post-update - a script that fires after the repo is updated
cd hooks
vim post-update
#!/bin/sh
export GIT_WORK_TREE=../../path/to/your/live/files
git checkout -f

STEP 4:

give hooks folder permission to fire

chmod ug+x hooks/*

STEP 5:

connect local repo to bare repo

git remote add staging username@server.com:your/path/to/repo

then when you want to push your commits to the bare repo:

git push staging

working with clients

  • keep them updated of your progress (transparency ftw)
     
  • helps you and your team be more agile
     
  • keeps you accountable!

questions?

links to check out

Thanks for being here!

- Aurooba Ahmed

@aurooba