git commit -m "Your WordPress blog under version control"
Brian Retterer
@bretterer
bretterer@gmail.com
What Is Version Control?
It is the management of changes to documents, computer programs, large web sites, and other collections of information.
HUH????
multiple version of the same
files on your computer.....
ONLY BETTER!!!!!
Does this look familiar?

Then you have used a form
of Version control!
I guess we are done!
OK... So lets look at GIT
What is git?
Git is a distributed version control system
with an emphasis on speed.
Created by Linus Torvalds (see: Linux)
Advantages of Version Control
- Keep track of what changed, who made it, and when it happened
- Easily roll back changes when necessary
- Makes it easier to collaborate with other developers
That's Great ...
but what about keeping wordpress in version Control?
Two Options
- Keep Theme/Plugin Only under version Control
- Keep Whole Wordpress Install under version Control
Advantages of Keeping only theme/plugin in GIT
- Smaller repository
- Easier to integrate into other projects
- Shared Easier
- Different Versions of wordpress core files
disADVANTAGES OF KEEPING ONLY THEME/PLUGIN IN GIT
- Different versions of wordpress core files
- Compatibility issues
- Possible differences between
development and production
ADVANTAGES OF KEEPING
Whole wordpress IN GIT
- Same core files between dev and prod
- Easier to spin up to a new server
(if db is set up on different server) - Best way to test core upgrades
disADVANTAGES OF KEEPING
WHOLE WORDPRESS IN GIT
- Database upgrade issues
- Harder to share a theme/plugin
- Have to set up .gitignore correctly
- Installing a theme/plugin on production is bad
The .gitignore file
# Exclude these files from the git repo
wp-content/upgrade/*
wp-content/uploads/*
sitemap.*
wp-config.php (optional)
# ...wp-content/backup, wp-content/cache, etc.
# Hidden system files
*.DS_Store
*[Tt]humbs.db
*.Trashes
# Include these files in previously blocked directories
!wp-content/uploads/.htaccess
Why I say wp-config.php is optional
// ============================
// = Custom Environment Setup =
// ============================
$environments = array(
'local' => 'mysite.local',
'development' => 'dev.mycoolsite.com',
'production' => 'www.mycoolsite.com
);
$server_name = $_SERVER['SERVER_NAME'];
foreach($environments AS $key => $env){
if(strstr($server_name, $env)){
define('ENVIRONMENT', $key);
break;
}
}
// If no environment is set default to production
if(!defined('ENVIRONMENT')) define('ENVIRONMENT', 'development');
switch(ENVIRONMENT){
case 'local':
define('DB_NAME', 'myCoolSite');
define('DB_USER', 'root');
define('DB_PASSWORD', 'root');
define('DB_HOST', 'localhost');
define('WP_DEBUG', true);
$table_prefix = 'wp_';
break;
case 'development':
....
break;
case 'production':
....
break;
}
CAUTION!!!!!!
ONLY DO THIS IF YOU ARE OK STORING YOUR PRIVATE INFORMATION (DATABASE USER/PASS) IN YOUR REPO
MAKE SURE IT IS PRIVATE!
Ways around this:
Keep a file out of the repo that contains the DB login info on the server and just include that in your wp-config
Why keep other things out?
# Exclude these files from the git repo
wp-content/upgrade/*
wp-content/uploads/*
sitemap.*
wp-config.php (optional)
# ...wp-content/backup, wp-content/cache, etc.
# Hidden system files
*.DS_Store
*[Tt]humbs.db
*.Trashes
# Include these files in previously blocked directories
!wp-content/uploads/.htaccess
Reduces size of repo
Git Commands
- git init: Initalizes a git repository
- git add: Adds files changes in working copy
- git commit: Creates a new commit to your working copy
- git status: Shows status of working copy
- git remote: Shows remote versions
- git push: Pushes your working copy to remote
- git pull: Fetches and merges from remote
- git log: Shows listing of commits
Good reference:
Aliases!!!!!!
Questions?
Brian Retterer
@bretterer
bretterer@gmail.com
Copy of git commit -m "Your WordPress blog under version control"
By Brian Retterer
Copy of git commit -m "Your WordPress blog under version control"
Slides from Dayton Wordcamp
- 801