UPDATE: Don’t follow this guide, look down in the comments and do what John suggested.  This totally screwed me up, as none of the changes I did before I created the branch came through in the merge.

I started working on a new feature for my product today, and realized after several hours that committing my code would be a bad idea.  The new feature is big enought that I should have started working on it in a branch, but I didn’t think of that early enough.  I thought there would be a simple way to “commit changes to a new branch”, but I wasn’t able to find any obvious way to do that.  Here are the steps I took to get this accomplished.

From trunk checkout with uncommitted files:

  • Copy current trunk to a new branch
    svn copy . /path/to/new/branch
  • Switch current working directory from trunk to new branch
    svn switch /path/to/new/branch
    This merged my current changes with the trunk
  • Mark new files to be commited|
    svn add /path/to/new/file
    For each file that needs to be added
  • Commit your new files
    svn commit
  • Switch current working directory back to trunk
    svn switch /path/to/trunk
  • Checkout your new branch to work in
    cd ..
    svn co /path/to/new/branch

That’s all there is to it.  If you know an easier way to do this, let me know.  I wonder if I had done the “svn add” commands before the switch if that step would have been unnecessary.