On Github stevegrunwell / wordpress-git
Steve Grunwell / @stevegrunwell
Play along at home! stevegrunwell.github.io/wordpress-git
This is not an "Introduction to Git"-type of course. While previous Git/version control experience is not required it is recommended!
Want to learn Git basics? Buy me a beer!
Jesse, it's time to code!
Version control is not meant to be a replacement for real, scheduled backups.
Since every little change is tracked, it's not a great place to do debugging. Avoid committing untested or broken code to the repository!
Bonus: Go home on time, free of headaches.
This strategy includes WordPress core and plugins in the repository.
Components could be adapted for another workflow that excludes these items.
# Keep these files out of the repo /wp-content/themes/twenty* /wp-content/upgrade /wp-content/uploads /sitemap.* /wp-config.php *.sql # Hidden files *.DS_Store *Thumbs.db *.sass-cache* *~imageoptim*
<IfModule mod_rewrite.c> RewriteEngine on # Attempt to load files from production if # they're not in our local version RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule wp-content/uploads/(.*) \ http://{PROD}/wp-content/uploads/$1 [NC,L] </IfModule>
Does the requested file exist in the local filesystem?
No more FTP-ing files to your dev/staging environments!
$ git clone {REPO} {DIRECTORY} $ cd {DIRECTORY} $ cp wp-config-sample.php wp-config.php $ vi wp-config.php
Defining these values in wp-config.php eliminate the need to edit these values in the wp_options database table
// NO trailing slash! define( 'WP_SITEURL', 'http://example.com' ); define( 'WP_HOME', WP_SITEURL );
This doesn't impact URLs already in post content!
Prevent non-developers from installing/updating plugins or themes.
// Disable the theme and plugin installers and editors... define( 'DISALLOW_FILE_MODS', true ); // ...or just disable the theme/plugin editor define( 'DISALLOW_FILE_EDIT', true );
WordPress automatic updates won't run when evidence of version control is found, which is pretty baller.
It's not necessarily a bad thing to enable them, either
$ git pull
…and that's it.
(unless you use better deployment tools)
Add to deployment script to ensure nothing has changed on server:
$ git ls-files -dmo --exclude-standard
Will be empty if there are unchanged files, easier than parsing git status
# Bail if there are modified files on the target server task :untracked_files do is_dirty = capture "cd #{current_path} && git ls-files -dmo --exclude-standard" abort "There are modified files on #{app_environment}, please commit or reset \ these before deploying!" unless is_dirty.empty? end before "deploy", "deploy:untracked_files"
Be sure to add REVISION to your .gitignore file!
Steve GrunwellSenior Web Engineer, 10upstevegrunwell.com@stevegrunwell