Skip to content

Instantly share code, notes, and snippets.

@kasparsd
Last active April 17, 2024 12:35
Show Gist options
  • Save kasparsd/3749872 to your computer and use it in GitHub Desktop.
Save kasparsd/3749872 to your computer and use it in GitHub Desktop.
Using Git with Subversion Mirroring for WordPress Plugin Development

Use GitHub for WordPress Plugin Development

We'll use the Easy Digital Downloads plugin as an example.

First, we need to get the revision number of the first commit to the WordPress SVN repo, because otherwise Git will try to go through all 100000+ commits in order to find it.

svn log http://plugins.svn.wordpress.org/easy-digital-downloads/

It is the last commit revision you seen on the screen:

------------------------------------------------------------------------
r529177 | plugin-master | 2012-04-09 19:36:16 +0200 (Mon, 09 Apr 2012) | 1 line

adding easy-digital-downloads by mordauk
------------------------------------------------------------------------

In this case it is r529177.

Create a local Git repository for the plugin and import the first commit from the SVN repository:

git svn clone --no-minimize-url -s -r529177 http://plugins.svn.wordpress.org/easy-digital-downloads/

which returns the following:

Initialized empty Git repository in /Users/kaspars/svn2git/easy-digital-downloads/.git/
r529177 = e18c66d09d77e4d8a923f2f300f73606791071e1 (refs/remotes/trunk)
Checked out HEAD:
  http://plugins.svn.wordpress.org/easy-digital-downloads/trunk r529177

Notice the --no-minimize-url flag which is required to stop git svn clone from moving into the base folder of the remote SVN repository and going through all plugins (see http://schacon.github.com/git/git-svn.html). We also use -s which is a shorthand way of setting trunk, tags, branches as the relative paths, which is the Subversion default (from http://schacon.github.com/git/git-svn.html).

Move inside the newly created Git repository:

cd easy-digital-downloads

and fetch all the other commits from the SVN repo:

git svn fetch

This step will take hours (!), so you can use the GIT_TRACE=2 flag before the the command to see a more verbose output:

GIT_TRACE=2 git svn fetch

Once this process is finished you have a complete Git commit tree for the project.

@L1fescape
Copy link

git svn rebase didn't work for me (it just hangs). I had to use git svn rebase --all

@idleberg
Copy link

i'm getting an error message after git svn rebase(and git svn rebase --all):

Unable to determine upstream SVN information from working tree history

will try and start over

@janfabry
Copy link

To speed up the git svn fetch, you can play with the --log-window-size=n parameter to request more commits per SVN request. The initial is 100, but I increased it to 10000 and found no problems - probably because the number of commits to your specific plugin compared to the whole WordPress plugin repo is so small. You can see the effect with tracing enabled: a lot less requests, but each request takes only a bit more time.

@janfabry
Copy link

The SVN tags are converted to Git branches, you can make real Git tags with the following command (based on
this git ready tip):

git for-each-ref refs/remotes/tags | cut -d / -f 4- |
while read ref
do
git tag -a "$ref" -m"Tag $ref" "refs/remotes/tags/$ref"
done

@rendom
Copy link

rendom commented Nov 21, 2013

@janfabry Is it possible to tag new versions in git then push them to wordpress SVN?

@loopj
Copy link

loopj commented Dec 19, 2013

@janfabry any advice on managing tags/releases? Ideally I'd like to do
git tag 1.0.0 and have that be reflected on the svn side

@loopj
Copy link

loopj commented Dec 19, 2013

git tag 1.0.0 && git svn tag 1.0.0 is the best i can come up with

@spinlock99
Copy link

I really like this for updating trunk but I don't see my assets directory (i.e. where I keep the screenshots for wordpress.org):

[~/svn]# ls
./  ../  .svn/  assets/  branches/  tags/  trunk/

[~/git]$git branch -a
* master
  test
  remotes/tags/1.0
  remotes/tags/1.1
  remotes/tags/1.2
  remotes/tags/1.3
  remotes/tags/1.4
  remotes/tags/1.5
  remotes/tags/1.6
  remotes/test/master
  remotes/test/test
  remotes/trunk

I can $ git svn dcommit from my git repo then # svn up from the svn repo and get all of the code changes in trunk. Then, I'm just managing tags in svn. Is there a better way to do this?

@kasparsd
Copy link
Author

kasparsd commented Feb 4, 2014

Oh, man. I wish there was some kind of comment notification for Gists. I never knew there were all these great comments until now when I find this article via a google search.

@kasparsd
Copy link
Author

kasparsd commented Feb 4, 2014

Thanks for the great suggestions @janfabry! I have included them into the article now.

@tripflex
Copy link

Don't forget to push tags to github:

git push --tags origin

using git push --all origin did not push the tags when I did it

@AliceWonderMiscreations

I had the same problem with git svn rebase hanging until I used the --all switch.

@tolvstein
Copy link

I am able to push new revisions to the trunk. I am however not able to create tags. Typing: git svn tag "1.0.0" returns the following error:

Authorization failed: POST of '/!svn/me': authorization failed: Could not authenticate to server: rejected Basic challenge (http://plugins.svn.wordpress.org) at /usr/local/Cellar/git/2.4.1/libexec/git-core/git-svn line 1196.

Did anyone of you experience this problem?

@lucaspiller
Copy link

I had to make a few changes to the script @janfabry included for converting tags correctly. I'm running Git 2.4.5, so maybe things have changed in the last two years :)

git for-each-ref refs/remotes/origin/tags | cut -d / -f 5- |
while read ref
do
git tag -a "$ref" -m"Tag $ref" "refs/remotes/origin/tags/$ref"
done

@polkan-msk
Copy link

How do you use GitHub if every time 'git svn dcommit' is called it overwrites SHA-1 hashes for all new commits?

@holisticnetworking
Copy link

There doesn't seem to be anything in this set of directions that addresses how I get access to my SVN repository. Just doing this command:
git svn clone --no-minimize-url -s -r529177 http://plugins.svn.wordpress.org/easy-digital-downloads/

Doesn't seem to quite cover it? Because then, when I go to commit changes to SVN, I get "No changes between 7cff1bf856e9b32a8c44d64675aae99b395ad2e6 and refs/remotes/origin/trunk"

What am I missing?

@fabacab
Copy link

fabacab commented Jan 3, 2016

I'm seeing the same problem described above by @tolvstein and am unable to create tags. The exact error I'm seeing is:

Authorization failed: POST of '/!svn/me': authorization failed: Could not authenticate to server: rejected Basic challenge (https://plugins.svn.wordpress.org) at /Applications/Xcode.app/Contents/Developer/usr/libexec/git-core/git-svn line 1217.

The same issue is described here, here, and here, but none of these other threads have any resolution. :(

@nuboa
Copy link

nuboa commented Jan 31, 2016

Any updates on this? I have the same problem and it's very annoying... :-(

@alexanmtz
Copy link

The correct is:

git svn clone -r529177:HEAD -s --no-minimize-url http://plugins.svn.wordpress.org/easy-digital-downloads/

@alexanmtz
Copy link

The solution described by @meitar that use svn cp it worked for me:

svn cp https://plugins.svn.wordpress.org/wp-agenda/trunk https://plugins.svn.wordpress.org/wp-agenda/tags/1.7 -m "creating tag 1.7"

It's not a real solution, but there's no way to authenticate using git svn tag.

@dortzur
Copy link

dortzur commented Jan 4, 2017

use git svn rebase --all

@sergeykuzmich
Copy link

You can use travis to deploy pluings and themes if you don't need to keep development history in SVN (keep it only in Git).
Here is a guide for it https://kuzmi.ch/articles/wordpress-plugin-and-theme-development-using-git-only/

@nolimitdev
Copy link

Is it possible to additionally "upload/sync" my git tags to SVN? I have created several tags only locally. As I understand git svn tag 1.1 creates tag only for current state (latest commit in SVN), it does not create tag for that local commit with the same local tag.

Btw when I use git svn tag 1.1 I get:

Authentication failed: No more credentials or we tried too many times.
Authentication failed at ...Git/mingw64/libexec/git-core/git-svn line 1196.

but git svn dcommit works well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment