SVN Workout 1 - Branch and merge practise

RECOMMENDED TO USE LATEST SVN CLIENT, 1.8.4 (at time of writing)

Version control is only as good as how it's used. And it can be used really badly. All the facilities are there to prevent trouble from occurring, but only if you use them.

A basic reliable version control workflow assumes that the trunk copy contains only stable production ready code.

To ensure only stable production ready code goes into the trunk, branches must be created to contain the work for each feature for a future release. Let's say that again:

To ensure only stable production ready code goes into the trunk, branches must be created to contain the work for each feature for a future release.

It's often tempting to just use the trunk for everything, avoid branching and merging to save time and hassle but that leads to bigger problems down the line and costs MORE time to later fix.

So to dispel the rumour that branching and merging is difficult, let's do a little svn workout to show how easy it can be, and how much hassle it can save when real world problems occur.

# First checkout working copy
svn co <remote repo path> branchpractise

# now we have a working copy of the trunk
# make a branch
# First ensure you are 'in' the working copy
# ^ means root url of working copy you are in
svn copy ^/trunk ^/branches/testbranch1 -m "Creating branch for ..."

# Now the branch is available on the server to use
# Switch the working copy to be this branch
# Good practise to only switch a clean working copy - ie no pending changes
svn status

# Should return nothing, so now make the switch
svn switch ^/branches/testbranch1

# make some changes!
svn commit -m "my change"

# Now we are done - need to merge our changes into the trunk.
# First switch back working copy to the trunk
# Again ensure working copy is clean
svn status



# Should return nothing, so switch back to the trunk
svn switch ^/trunk

# Now merge the branch that exists on the server into your local copy of the trunk
# First ensure the working copy is upto date, so you are merging into the latest and greatest version of the trunk.
svn update
svn merge ^/branches/testbranch

# Now handle any conflicts that may occur, and do any final integration tests
# When it's stable commit the branch to the trunk
svn commit -m "Merging testbranch into trunk"

# For further reading from the horses mouth:
svn help co
svn help commit
svn help copy
svn help merge 
# (^^ lots here!)

Tags: svn