Notes on the “WordPress and Git” video series by Amelia Briscoe (Part 1)

These are my reference notes on the excellent video series WordPress and Git by Amelia Briscoe. Many thanks to Amelia for creating this series, sharing it and allowing me to post this summary. This post covers the first four videos. My second post (Part 2) will cover the last five videos.

Links

Contents

 

Video 1. Importing a WordPress Git Repository

Mark Jaquith’s WordPress Skeleton –  A basic layout of a WordPress Git repository

Features of WordPress Skeleton

  • Latest version of WordPress is in the sub module wp
  • All the content (themes, plugins and “must use” plugins) are in the content folder
  • .gitignore tells git to ignore certain files
  • .htaccess
  • local-config-sample.php
  • wp-config.php

Importing WordPress Skeleton into Bitbucket

  • Select Import an existing repository in Bitbucket
  • Copy the URL of WordPress Skeleton (https://github.com/markjaquith/WordPress-Skeleton.git) and paste it into the URL for the Old repository on Bitbucket
  • Enter a name and description for the New repository and click Import repository

 

Video 2. Clone a WordPress Git Repository to a local server

Forking the repository for local use

  • When importing is finished, fork the new Bitbucket repo for use in local environment by clicking the Fork button near the search bar
  • On the next page, enter a name (eg. development-repo) and description for the repo and click Fork
  • Once the forking is complete, copy the HTTPS URL for the newly forked repo from the top right hand corner of the screen
  • Open the git terminal and navigate to the folder that you want clone the repository into (eg. C:\xampp\htdocs)
  • Run your own version of the following git command
git clone --recursive https://benpearson@bitbucket.org/benpearson/development-repo.git wp_development

Explanation of the git clone command

  • recursive tells git to clone the sub module wp in the WordPress Skeleton as well.
  • https://benpearson@bitbucket.org/benpearson/development-repo.git is the HTTPS URL of the repo to be cloned.
  • wp_development is the name of the folder that will be created for the cloned repo. If this argument is omitted git will give the folder the same name as the repo.

Finish cloning repo and create a database

  • Enter Bitbucket password and wait for cloning to complete (takes a couple of minutes)
  • Open phpMyAdmin on your local server and create a database and user for the WordPress install.

 

Video 3. Configure the WordPress Git Repository

Consider the following code from the top of the wp-config.php in the newly cloned local repo.

if ( file_exists( dirname( __FILE__ ) . '/local-config.php' ) ) {
    define( 'WP_LOCAL_DEV', true );
    include( dirname( __FILE__ ) . '/local-config.php' );
} else {
    define( 'WP_LOCAL_DEV', false );
    define( 'DB_NAME', '%%DB_NAME%%' );
    define( 'DB_USER', '%%DB_USER%%' );
    define( 'DB_PASSWORD', '%%DB_PASSWORD%%' );
    define( 'DB_HOST', '%%DB_HOST%%' ); // Probably 'localhost'
}

This code looks for the file local-config.php. If it exists, the database information contained in the file in local-config.php is used. If it does not exist, the database information listed below the conditional (above) is used. The file local-config.php will not exist in the repository because it is listed in the .gitignore file.

.gitignore also contains /content/upgrade/ so that any WordPress upgrades made in the local environment will not be pushed to the repo

Setting up the config files

  • Create a copy of local-config-sample.php and rename it local-config.php
  • Open the new created local-config.php and enter the local database name, user name and password.
  • Open wp-config.php and find the Custom Content Directory section. Edit the following line to include your local folder name
define( 'WP_CONTENT_URL', 'http://' . $_SERVER['HTTP_HOST'] . '/content' );

Should be changed to something like following (where wp_development is the name of my local folder)

define( 'WP_CONTENT_URL', 'http://' . $_SERVER['HTTP_HOST'] . '/wp_development/content' );
  • It may be necessary to increase the PHP memory limit. This done by adding the following constant definition above the Custom Content Directory section in wp-config.php
define('WP_MEMORY_LIMIT', '96M');

 

Video 4. Installing WordPress from a Git Repository

  • Running git status now in our repo folder will report that wp-config.php has been modified and it is not yet staged
  • Run git add . to add everything to the staging area
  • Run git commit -m "Changes to the wp-config file"
  • Open your own version of the URL localhost/wp_development/wp/wp-admin in a browser. This should open the 5 minute WordPress installation screen.
  • Complete installation as usual and login
  • Go to Settings->General in the WP dashboard and remove the wp from the end of the Site Address (URL).
  • Update permalinks to your desired structure
  • Opening the termial and running git status now will report that .htaccesshas been modified
  • Run git add .

You may get the following message if using Windows:

warning: LF will be replaced by CRLF in .htaccess
The file will have its orginal line endings in your working directory

In Unix systems the end of a line is represented with a line feed (LF). In windows a line is represented with a carriage return (CR) and a line feed (LF) thus (CRLF). When you get code from git that was uploaded from a unix system they will only have a LF. It’s nothing to worry about. More information on this warning from stackoverflow

  • Run git commit -m "Updated permalinks"
  • Run git log --oneline -5 to display the information for the last 5 commits, one per line.
  • Run git push to push the changes to your Bitbucket repository.

4 thoughts on “Notes on the “WordPress and Git” video series by Amelia Briscoe (Part 1)

  1. Bis

    Thank you so much for making these notes and saving me having to make notes. What a wonderful thing to do – thank you from the bottom of my heart again!

    Reply
  2. RHF

    Ben,

    I just decided to try out Git with WordPress and thought it would be difficult and time consuming to get started. Fortunately I stumbled upon this site and decided to give it a try. I already had a Bitbucket account so I just followed your instructions, step-by-step. I was amazed that everything was clearly explained and the entire procedure went perfectly. (Well, actually it took me a while to find the Fork button on Bitbucket.)

    Well done, sir! And thanks for a very useful and clear set of instructions.

    Bob

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *