SVN Branching as easy as Git

SVN branching is a little super painful on the command line. For all those who worked with git a single minute of their lives, it’s really frustrating. Floor Drees wrote a nice svn tutorial for git users. But it doesn’t need to be so complicated. This post provides handy bash aliases (they work on zsh, too) for easier svn branching, merging and reintegrating.

The SVN problems

Who can remember the whole repository URL which is in fact needed twice for creating a new branch?

svn copy \
http://repo.domain.com/svn/project-x/trunk \
http://repo.domain.com/svn/project-x/branches/easter-egg \
-m "Creating private branch for feature easter egg"

I mean, that’s ridiculous long and most of the time there are no tab completion possibilities. The same applies for reintegrating a branch back into the trunk:

svn merge --reintegrate \

http://repo.domain.com/svn/project-x/branches/easter-egg

svn ci \
-m "Reintegrating private branch for feature easter egg into trunk"

But why doesn’t svn use the base repository URL as prefix? Nobody knows.

The solution – make SVN less painful

Add the svnaliases from my github repo, save it into your home and add it to your dotfile and there we go:

create a branch:

svnbr "branchname" "commit message"

update a branch from the trunk:

svnupbr

delete a branch:

svndelbr $branchname

switch between trunk / branches:

svnsw trunk
svnsw branches/$branchname

Reintegrate a branch back into the trunk:

svnre $branchname "commit message"

Getting more productive

With those fancy aliases it’s super easy to use SVN branching. Save a lot of time during branching and reintegrating – go polish your product instead!

Disclaimer: yes, there are git svn-bridges, but not every (industry) project can switch source control systems in short period of time. And please no git vs svn rants – this post is about getting more out of SVN, not exchanging SVN with Git ;-) .

 

About the Author

Gregor is Co-Founder and CTO of Usersnap, a startup which transforms the way customers and users get in touch on the web by providing visual feedback tools. You can try Usersnap right on this blog! And psst РUsersnap offers 15 free trial Рno credit card required.

This entry was posted in General and tagged , , , , . Bookmark the permalink.

2 Responses to SVN Branching as easy as Git

  1. Daniel Shahaf says:

    Actually, Subversion has supported ^/trunk instead of svn://URL/to/repos/root/trunk for a few years now. The latest release prints those shortened URLs in ‘svn info’. For example:


    $ svn checkout http://svn.apache.org/repos/asf/subversion/trunk
    $ cd trunk
    $ svn switch ^/subversion/tags/1.8.0
    $ svn info | grep "Relative URL"
    Relative URL: ^/subversion/tags/1.8.0

    Furthermore, the –reintegrate is deprecated as of 1.8.0 and should be omitted when using 1.8 or newer clients. See
    http://subversion.apache.org/docs/release-notes/1.8#auto-reintegrate

    The github aliases you point to assume Subversion 1.6 or earlier is used. That line of releases has been deprecated for 21 months.

    All that said, if your aliases make someone’s life easier, good for you. :-)

    • Thanks for pointing that out! Unfortunately, Debian + Ubuntu are way behind new subversion releases, therefore it’s sometimes handy to use aliases instead of self compiled svn packages.