Git version control and WordPress

I use Git for pretty much any decent sized coding project I do, and that includes WordPress sites. There are a number of different ways to set things up, but I thought I’d share mine as I think it’s the cleanest and nicest way to go about it. …although I would, wouldn’t I!

First thing: Don’t keep the core files under version control. WordPress has a great update system baked in so this is not necessary.

Second thing: Make sure you can bring anything you wrote yourself under version control. As well as the template, you may make custom site specific plugins, have special things going on in your .htaccess etc. etc.

So, make a new git repo, copy the core files into it, tell git to ignore them all with .gitignore and start to commit and push our own code.

Make yourself an ssh key pair:

[bash]ssh-keygen -t rsa[/bash]

Accept the defaults, get the new public key:

[bash]cat ~/.ssh/[/bash]

Copy that into Github or Beanstalk or wherever your repository is hosted.

Now lets put it up on a server. As Git doesn’t like cloning into non-empty directories, we need to download the wordpress core into a separate dir and merge it in using rsync (mv will not work here):

[bash]cd /var/www/your_site
git clone html
rsync -a wordpress/ html/
rm -rf wordpress[/bash]