Using git for WordPress development

Tagged git Tagged WordPress

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

Update:
The git svn init + git svn fetch takes forever on the WordPress repository. Instead, use svn log http://svn.wp-plugins.org/your_plugin to get the correct revision number and git svn clone http://svn.wp-plugins.org/your_plugin -rYOURREVISION.

This will initialize a local git repository. Inside the repository, use

git svn fetch
git gc
git branch -a

The first command will take a few minutes and fetch all tags, branches etc. from the svn repository. The second command cleans up your git repository. This will significantly reduce it’s size. The last command will list all branches, local and remote. To track the remote trunk in a local branch use

git checkout -b svn-trunk trunk

svn-trunk is just the name the local branch gets in this example, you can use anything you like.

A normal workflow usually looks like this:

git checkout -b newbranch # create a local branch that you edit
... edit ...
git commit -m "Added awesome new feature" -a
git checkout svn-trunk
git merge newbranch
git svn dcommit

These commands create a local branch where you can try new things. Commit the changes to your local branch. Then check out the local svn-trunk branch that tracks the remote WordPress repository, merge the changes from newbranch. Then rebase the svn branch to the subversion trunk. The last command will update the remote svn trunk, assuming you really named your local trunk branch 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.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, as git-svn has some limitations: Only use the described workflow if you’re the only commiter and work with one git repository.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

Related posts:

  1. Git clone, ssh: Could not resolve hostname

5 Comments

  • Posted by Brown on 11. November 2009 at 15:49.

    I added your blog to bookmarks. And i’ll read your articles more often!

    • Posted by Nicolas on 11. November 2009 at 15:53.

      Thanks Brown! What a nice comment. Too bad I had to remove all the viagra links :-(

  • Posted by Mario Santagiuliana on 11. March 2010 at 02:03.

    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.

    • Posted by Nicolas on 13. March 2010 at 12:51.

      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).

  • Posted by Mario Santagiuliana on 13. March 2010 at 13:21.

    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.

Leave a Reply

Your email is never shared. Required fields are marked *

*
*