Managing a WordPress plugin with SVN and Git

I’m not trying to torture myself — which is why for the past 18 months managing my plugins in the WordPress SVN repository has been separated from my development work which is all saved in Git (Bitbucket to be totally honest).

The time has come to find out just what ‘git svn‘ is all about and see if I can make it work!  I’ve yet to become a master or ninja of Git .. but thanks to persistence on my part in setting up continuous integration with Jenkins and automated testing with Selenium I’m getting to know Git more.

How to manage a Git SVN WordPress Plugin Repo

Get Ready — Migrating away from Subversion

You have to assume you already have a WordPress SVN plugin repo … otherwise what are you reading this for :)

It doesn’t matter if you use Bitbucket, Github or something else. Essentially we are going to setup a Git repo on your local machine, checkout the code from WordPress SVN and then pull in your code from Bitbucket.

This is going to use my WordPress plugin DBC-Backup 2 so you just need to replace it with your plugin name.

SVN WordPress Plugin Log and History

We need to find the earliest commit on the WordPress SVN repo for your plugin so that we don’t end up spending days checking out all the code from SVN.

Open Terminal or your CLI …

svn log http://plugins.svn.wordpress.org/dbc-backup-2

(hint: your WordPress Plugin SVN URL should look like mine, except with your plugin name)

Depending on how much you have used your SVN repo, this could take awhile … but you’ll get a list of all your commits

What you are looking for is the 1st commit like this:

------------------------------------------------------------------------
r570197 | plugin-master | 2012-07-10 18:57:59 +0100 (Tue, 10 Jul 2012) | 1 line
adding dbc-backup-2 by damiensaunders
------------------------------------------------------------------------

SVN Log

GIT SVN Clone

Now navigate to where you want your plugin repo on your local machine (hint all my plugins reside inside the wp-content/plugins folder).

git svn clone -s -r570197 http://plugins.svn.wordpress.org/dbc-backup-2

-s = The SVN repo is in standard layout (trunk, branch, tags)
-r = start from revision

Git SVN Clone

Hint: don’t do this without a revision, or you could be waiting days as your local machine scours the whole of the WordPress Plugin SVN repo.

I tried using

git svn clone -s -rxxxxxx --no-minimize-url

but that ended up generating an error so I don’t use that switch

Now you just need to change directory and fetch everything from your SVN repo like this:

cd plugin-name/
git svn fetch

What this is doing is getting all commits starting from revision r570197 when my plugin was first created.

Even starting from the revision, this takes a bit of time (20 – 30 mins was enough for my plugin). The screen will start filling up with info on each file if it was A(dded) or M(edified).

When its done, you’ll have a new folder on your local machine with all your SVN contents (except no Tag or Branch folders and no ‘assets’ folder).

Add Bitbucket to your new Git SVN Repo

This way you can start to pull down your code (if it already exists in Git).

git remote add origin git@bitbucket.org:damien1/dbc-backup.git

Hint: you can use the same command for Github, etc.

Git SVN add remote

Git Rebase

We’ll do a bit of a clean up and check

git svn rebase

This should be quick … we’ve not done any local changes yet and hopefully no-one else committed to WordPress SVN :)

Merge Git and WordPress SVN

This is the powerful command which does a lot of good work

git pull –rebase origin master

Git SVN Pull

What will happen is that Git will pull everything from your Git remote that we added (called origin) and it start to match and check your SVN. It’s very likely you’ll have merge conflicts and will need to resolve them … which is easy to fix!

Git SVN Pull Err

If you don’t have any merge errors you’re a Saint!

If you do have errors — then its time to launch your fav Git app and do some visual diff / detective work.

Bitbucket and SourceTree

I’m a fan of a SourceTree and use it for most of my work — my Git friends tell me I should do more from the CLI, but thats never going to happen. SourceTree does work with Github too.

So now you can open SourceTree and just add a new Repo from the local working copy.

Git SVN SourceTree Add

SourceTree

Now you’re done … you can go about your dev work and safely use Git to commit to Origin

Remember to not commit often to SVN as it will affect your trunk for one thing!

SourceTree Git

Bitbucket — SourceTree SVN Fail?

SourceTree has an option to clone from SVN. I thought I’d be smart and try to clone from WordPress SVN repository for my plugin. But it failed me.

Further Reading

http://danielbachhuber.com/2010/09/29/how-to-properly-use-git-with-wordpress-org-subversion/

1 Comment

  1. James December 3, 2013 at 3:39 pm #

    Cheers, seems to work well! I did have to run through this as well though: http://blog.victorquinn.com/fix-git-svn-in-mountain-lion

    Reply

Leave a Reply

Read previous post:
feature_dbc-backup
DBC Backup 2 v2

Carry on from other news this week about my WordPress plugins ... DBC Backup 2 will be getting an update...

Close