Skip to content

Instantly share code, notes, and snippets.

@MWins
Last active January 25, 2017 02:12
Show Gist options
  • Save MWins/b51c977f28a94dc098b7 to your computer and use it in GitHub Desktop.
Save MWins/b51c977f28a94dc098b7 to your computer and use it in GitHub Desktop.
git with wordpress-workflow

Using GIT with Wordpress - Workflow

Git is a source code control system. GitHub and BitBucket.org provide git support as part of their service. Github's free tier requires public repos. Bitbucket.org will let you create private repos on the free tier. You will need the git software along with an account at one of those providers to use these guide.

Details about starting with Source Code Control can be found in this gist : Source Control Start , this includes links to software and tutorials.

how does it help or what's the workflow...

First off, git should not be used as a backup tool. Media resources like images,videos,audio, etc, should not be placed into a git repo. Wordpress itself should not be part of a repo. Nor should it include any code which can be 'managed' via tools like composer.

The two areas of development addressed are Wordpress themes and plugins. Each of these can be either for a client or for general release.

Themes

You create a repo for your base theme. Could be as simple as a style.css. For a new project, you fork the base template into a new repo. This becomes where you work. You checkout the new project and develop locally as normal. When done you commit the changes back to the new project along with a commit message. As you work on the project, you push commits to the repo. This gives you a log and you can revert back to previous changes if something goes wrong or changes.

This is a stub Wordpress theme, it only has style.css, index.php, functions.php and custom-page-template.php. It has no code. style.css has blank header information. custom-page-template.php has the required php tags and template name section which needs to be completed with the template name.

github - Wordpress Basic Theme

bitbucket - Wordpress Basic Theme

Note: GitHub doesn't allow for 'fork' and renaming a repo you own. It's possible via git but that's extra steps. Can use a 'branch' to create the new project but that is less than ideal. BitBucket does allow you to fork and rename your repos from the web interface. Project repo is now in both locations.

The project is done and the client needs to review it for approval. Create a release. Call it 'revision 0'. Checkout the project, push it to the server for the client to inspect. They respond with 'great but ...' there's a list of issues to fix.

Wordpress Basic Theme - Version 1 The button 'Draft a New Release' let's you create a new release and provides an archive file for download if needed.

Well first off, both github and bitbucket offer issue trackers. You can put the issues into the tracker and use it as a todo list or if the client's hip to git, they could just post the issues themselves. Unlikely on the later but anyway. It's a bonus.

Issue Tracker for the sample project

You go in and fix the issues. Create/tag a new release and go through the same process. This becomes revision 1. Repeat until client is happy.

That's a basic level. Doesn't include the concept of branches. Branches let you checkout the code make changes and save them independent of other branches. You would have a 'master' branch and you create a 'dev' branch. Work on the dev branch doesn't change 'master' until you merge them. This lets you work on the code base in numerous ways. This is more useful when working with released software. The master branch would be the current version while the next version is being developed in a branch. And it's extremely useful when working with other people since they can fork the code base and make 'pull requests' to merge into a branch.

To create a new branch, from the repo source code page click the branch button beside the project name. Type in the name of the new branch and github will create it for you if it doesn't exist.

DEV branch

This branch wil be for a child theme template. Means we need to add to the style.css header, add some code to functions.php and remove the index.php.

Here's the release -child theme

And all project Releases

Does it take some extra work? yes. Is it worth it? Yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment