WordPress 2.7 was recently released so I started the process of updating the handful of WP instillations that I manage. Git has made this process a breeze! Here’s how I do it.
- To start a new project, use subversion to download the latest stable release of WordPress
- Add that entire directory, including the .svn folders, to git. To keep subversion happy, make sure that all of the svn tmp directories are in git (use an empty .gitignore file to force git to add empty directories)
- Before you make any changes, create a new branch in git called wordpress_base. You should never do anything with this branch other than update the WordPress code from subversion.
- Switch back to master and change whatever needs changing (e.g. add themes, plugins, etc.). To make upgrades go as smoothly as possible you shouldn’t modify the base WordPress files more than you absolutely have to but, adding themes and plugins should be no problem.
- When everything is tested and ready to deploy, commit everything to git and push to the webserver
The command line will look something like this:
$ cd ~/Downloads $ svn co http://svn.automattic.com/wordpress/branches/2.6/ new_blog $ cd new_blog $ git init $ git add . $ git commit -m "Import WordPress 2.6" $ git branch wordpress_base ## Get the site completely setup, commit everything to git and ## push everything up to the server.
When you’re ready to update WordPress:
- Checkout the wordpress_base branch
- Either ‘svn up’ or ‘svn switch’ to get the newest code
- Check all of the changes in to git
- Merge wordpress_base back in to master (I generally rebase then merge)
- After everything in git has been committed, push, pull or do whatever fits your process to get the updated code from your development machine to the server
- Don’t forget to upgrade your blog database after the new code has been deployed by going to: http://myblog.com/wp-admin/upgrade.php
$ git checkout wordpress_base $ svn switch http://svn.automattic.com/wordpress/branches/2.7 $ git add . && git ls-files --deleted | xargs git rm $ git commit -m "Updated WordPress to version 2.7" $ git checkout -b integration $ git rebase master $ git checkout master $ git merge integration $ git branch -d integration ## Make sure all conflicts have been resolved, test the new site and ## update plugins. Commit changes to git and push them to the server.