Using git for WordPress development
git is a powerful revision control system. It is a distributed system. This means that you can commit, create branches or tags on your local hard drive without any network connection. Read more about git on the project's website, there's also great documentation there.
If you write WordPress plugins and want them to be published on the WordPress plugins page you have to use svn which can be painful once you're used to git.
Fortunately, git can interact with svn via git-svn. Here's a list of the commands you will need to use.
git svn init -s http://svn.wp-plugins.org/your_plugin
This will initialize a local git repository. Inside the repository, use
svn log http://svn.wp-plugins.org/your_plugin
The svn command lists the svn revisions. You want to write down the number of the latest commit. Then,
git svn fetch -rNNNNNN
git gc
git branch -a
Replace NNNNNN with the appropriate revision number from the svn output. The first command will fetch the svn trunk. The second command cleans up your git repository. The last command will list all branches, local and remote.
Notice: If you get the error fatal: refs/remotes/trunk: not a valid SHA1 you probably tried to check out a revistion that was a tag. This seems to be a bug in git svn (confirmed up to 1.7.2.3). The workaround is to fetch the previous revision, one that is not a tag.
A normal workflow could look like this:
... edit ...
git commit -m "Added awesome new feature" -a
git svn dcommit
The last command will update the remote svn trunk. As we're talking about WordPress plugins you'll want to tag your commit so that older versions of your plugin can still be downloaded.
git svn tag version
This will create the tag in the remote svn repository. It looks like this is only possible since git 1.6.1. For Debian Lenny systems you'll need git from backports.debian.org for this to work.This should get you started with git and WordPress plugin development. Please do read the git documentation for more details.
I added your blog to bookmarks. And i'll read your articles more often!
Thanks Brown! What a nice comment. Too bad I had to remove all the viagra links :-(
Hy, I have just create my wordpress plugin (wp-itheora) and I public it on github:
http://github.com/marionline/wp-itheora
Now I want to public it on wordpress plugin direcotory. I have ask it and they give me this url:
http://plugins.svn.wordpress.org/wp-itheora/
How can I put my plugin to svn repository with git?
I try:
$ git svn init -s http://plugins.svn.wordpress.org/wp-itheora/
Then with "git svn dcommit" I have got this error:
Unable to determine upstream SVN information from HEAD history.
Perhaps the repository is empty. at /usr/libexec/git-core/git-svn line 511.
If I run git svn fetch I wait 3 hours...then I kill it...
I don't understand how use git-svn to put my plugin in the official directory.
Thank you very much. Sorry for my bad english.
Hello Mario, hmmm, I haven't used git to do the initial commit yet. But I would have assumed that it just works...
Are you sure you waited three hours for the fetch? It is rather slow, yes, but three hours seems excessive (unless you're on a very slow connection).
Thanks for your answare.
No slow connection.
I resolve the problem with:
$ git svn fetch -r HEAD
With only git svn fetch, git try to search in all svn tree I think...
Thank you very much.
I love GIT. I use it for Wordpress and Drupal development. Drupal 7 is officially moving over to it from CVS.
On a wordpress note, I have an automated development -> staging -> live setup as described here: http://robmalon.com/moving-a-wordpress-database-between-live-development-staging-environments/
I didnt go into details about GIT, but you can also setup commit and push hooks to automate that even further. Bit of Shell scripting and usage of rsync too. Worth looking into if you've never tried it or heard of rsync.