How to create a branch of a Subversion repository

I’m mostly posting this one because I constantly forget and don’t wanna waste another 10 minutes finding it in some 947-page technical pdf, know what I mean?

You can do this from either your remote server OR your local machine.  It’s alot faster to do it from your remote server, but if you want or need to run these commands from your local machine, for example, to backup the latest version/revision to your local machine, to update your local working copy, and probably most commonly because you’re usually already working with your local “working” copy, so it’s easier just to run these commands from there - a few less clicks never hurt anybody, and more time for coffee re-heating.

#1 - First, you simply want to checkout your whole project repository into a temporary (local or remote) directory, which I’ll call “deleteme” so we know we can delete it later and it won’t affect anything.  Make sure to specify the repository’s “root” directory so you checkout the whole svn project, meaning not just the “trunk” directory, but the “tags” and “branches” directories too.

# precautionary clean up of delete-able files and/or directories

rm -rf ~/delete*

# I am using svn+my_ssh to connect (like most of the tutorials demonstrate on this website), but you may have a different connection method, so substitute the prefix to fit your needs:

svn co svn+my_ssh://mydomain1.com/home/super/rep/svn/myproject1 ~/deleteme

#2 - Next, now that we have the whole repository in a temporary “deleteme” folder, we can “checkout” any version we want to tag as a branch (usually the /trunk folder, but perhaps you need a specific revision or are not tagging the trunk for this exercise).  What you name your branch is up to you, but may I recommend a sequential versioning approach?

svn copy ~/deleteme/trunk ~/deleteme/branches/myproject1-2.0.2

#3 - Time to commit this new branch to the repository once we confirm the svn status

svn status
#  A  +   branches/myproject1-2.0.2

svn commit -m “branched revision 11479 into version 2.0.2″
#  Adding   branches/myproject1-2.0.2
#  Committed revision 11480.

#4 - Alright! That was painless.  Now we have a new branch called myproject1-2.0.2 that was branched from trunk revision 11479.  All we have to do now is clean up our “deleteme” folder and call it a branch.

rm -rf ~/delete*

Done!

Leave a Comment

Name: (Required)

E-mail: (Required)

Website:

Comment: