Like this tutorial? Check out my updated and more comprehensive Git/Github/wordpress.org tutorial at https://teleogistic.net/2011/05/revisiting-git-github-and-the-wordpress-org-plugin-repository/.
I’m on a never-ending quest to come up with a good local environment that will support the kind of WordPress plugin development that I enjoy So Very Much. I’ve only just recently begun using Github for version control and already I can’t imagine living without it. But doing WP plugin development in Github is not totally straightforward, because wordpress.org’s plugin repository uses SVN. When it comes time to release a new version on the wordpress.org repo, it’s simply not practical to merge changes manually and manage two different version histories. I wanted a setup where I could use Github for everyday development, but would connect to WP SVN when I was ready to release.
There are lots of posts out there on how to use git-svn:
- Stas figured it out for BuddyPress Courseware
- Nicolas Kuttler on Using git for WordPress development
- Evgeni Golov on using plugins.svn.wordpress.org with Git
I couldn’t get any of the methods to work the way I wanted. But by mashing a few of them together, I have what is, I think, a workable setup. Here are the steps.
- If you don’t already have one, create a Github repository for your work. I’ll assume here that you have configured Git on your machine, with git-svn installed as well.
- Create a directory for your working copy. I use several local WP installations for plugin development, the main one of which is named Doris. So I’d do the following, for an imaginary plugin I’ll call awesome-plugin:
cd /sites/doris/wp-content/plugins mkdir awesome-plugin
- Before connecting to WP SVN, it’s a good idea to check for the revision number of your most recent commit. If you don’t, git-svn will sift through all 280,000+ revisions on svn.wp-plugins.org.
svn log http://svn.wp-plugins.org/awesome-plugin
Scroll to find the most recent reversion number. Let’s say that in this case it’s r287228.
- Clone the svn repository to your newly created directory. Because I want this working copy to actually work as a WordPress plugin, I’m not going to check out the entire awesome-plugin tree. Instead, I’ll just get the trunk, and when I want to tag new versions of the plugin, I’ll do it in a separate working copy on my machine. (This is perhaps not the ideal way to work, but for me it works – probably irrationally, I like having “clean” instances of the trees somewhere on my machine that are used only for tagging new versions.)
git svn clone http://svn.wp-plugins.org/awesome-plugin/trunk awesome-plugin -r287228
git svn clone will create the git-svn link and then do the initial fetch into the awesome-plugin directory.
- Depending on how you’re planning to use Git, you might want to create a branch that tracks the svn trunk, just for stable svn releases:
cd awesome-plugin git checkout -b svn remotes/git-svn
- Now that we’ve connected Git to WP SVN, we can connect to Github:
git remote add -f origin firstname.lastname@example.org:boonebgorges/awesome-plugin.git
I’m calling Github ‘origin’ because I’m so used to push and pulling to and from ‘origin’, but you can call it whatever you want. Of course, make sure to change ‘boonebgorges/awesome-plugin.git’ to reflect your username and repo name.
- Let’s test the connections. If your Github repo is empty, you can push stuff up right away:
git push origin svn
Remember that I am working on a branch called ‘svn’; you might use ‘master’ or something else altogether if you’d prefer. If your Github repo already had some files in it, you might find that you have to pull and merge them before pushing. Now make a change to your local:
touch test.txt nano test.txt # Type something in the document and save it git add . git commit -m "testing git-svn" git push origin svn
- Finally, let’s test to make sure that we can commit to SVN.
git svn dcommit
The first time you try this, you will be prompted for your wordpress.org password. If your local username is not the same as your wordpress.org username (mine isn’t), just hit enter and SVN will ask for your full creds. You should get a “Committing to…” message, followed by “Committed r123456” or something along those lines. You can check to see that your commit has gone through by visiting http://svn.wp-plugins.org/awesome-plugin/trunk in your browser.
“Because I want this working copy to actually work as a WordPress plugin, I’m not going to check out the entire awesome-plugin tree.”
I am using just git, but there is another way to that regardless of the scm. Just create a symbolic link for the actual plugin folder in /trunk into your local wp install. I use in order to have all my repos in one folder and duplicates of working websites to work on in another location.
Brilliant suggestion! I’m going to try setting that up right away.
Pingback: Tips and treats, no tricks around here: Friday Find « Premium BuddyPress Themes at BuddyDress
Pingback: 15 Awesome Free Tools That Will Make Your WordPress Life So Much Easier | WordPress, Multisite and BuddyPress plugins, themes, news and help – WPMU.org
Pingback: SFCite | Blog | 15 Awesome Free Tools That Will Make Your WordPress Life So Much Easier
Pingback: Git to SVN: Automated WordPress Plugin Deployment | I Blog
Pingback: Teleogistic / Revisiting Git, Github, and the wordpress.org plugin repository
Pingback: Git to SVN: Automated WordPress Plugin Deployment | Website live in a day
Pingback: Roundups here:
Pingback: Moved my WordPress plugins to GitHub | Coen Jacobs
Pingback: How to properly use Git with WordPress.org Subversion | danielbachhuber
Pingback: Moved my WordPress plugins to GitHub - Coen Jacobs