Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

svn branching best practices (in practice)

You want to make a Subversion branch, and merge it later. You read the branching
section in the official book, but are still confused. What to do?
creating the branch
1. Note the current head revision:
svn info svn://server.com/svn/repository/trunk | grep Revision
2. ake a clean, remote co!" of trunk into the branches folder. Name it something. We#ll
call it your_branch:
svn cp svn://server.com/svn/repository/trunk \
svn://server.com/svn/repository/branches/your_branch \
-m "Branching from trunk to your_branch at H!"_R#$%$&'"
$e!lace H!"_R#$%$&' with the revision number "ou noted in ste! 1.
Note that a backslash %\& means that the command continues onto the ne't line.
(. s(itch "our local checkout to !oint to the new branch %this will not overwrite "our
changes&:
svn s(itch --re)ocate \
svn://server.com/svn/repository/trunk \
svn://server.com/svn/repository/branches/your_branch
You don#t reall" need the --re)ocate svn://server.com/svn/repository/trunk bit,
but )#m in the habit of being e'!licit about it.
*. +heck that "our local checkout is definitel" now your_branch, and that "ou can u!date
ok:
svn info | grep *R+
svn up
,. commit "our new changes.
%-hese ste!s will work even if "ou had alread" made local changes on trunk, but decided
"ou wanted them on your_branch instead. )f "our trunk checkout was unmodified, .ust ski!
ste! ,.&
updating the branch
You#ve been develo!ing for a while on your_branch, and so have other !eo!le on trunk, and
now "ou have to add their changes to your_branch.
1. /irst, up,ate "our branch checkout and commit an" outstanding changes.
2. Search the Subversion log to see at what revision number "ou last merged the changes
%or when the original branch was made, if "ou#ve never merged&. -his is critical for
making a successful merge:
svn )og --)imit -.. | grep -B / your_branch
(. 0lso note the current head revision:
svn info svn://server.com/svn/repository/trunk | grep Revision
*. erge the difference of the last merged revision on trunk and the head revision on
trunk into the your_branch working co!":
svn merge -r +!%0_1R2"_R#$%$&':H!"_R#$%$&' \
svn://server.com/svn/repository/trunk .
$e!lace +!%0_1R2"_R#$%$&' with the revision number "ou noted in ste! 2, and
H!"_R#$%$&' with the revision number "ou noted in ste! (.
Now look for errors in the out!ut. +ould all files be found? 1id things get deleted that
shouldn#t have been? a"be "ou did it wrong. )f "ou need to revert, run svn revert -R 3.
,. 2therwise, if things seem ok, check for conflicts:
svn status | egrep 456|5.64
svn branching best practices (in practice) snax http://blog.evanweaver.com/2007/08/15/svn-branching-best-practices-i...
1 z 2 24.1.2012 16:32
$esolve an" conflicts. ake sure the a!!lication starts and the tests !ass.
3. commit "our merge.
svn ci -m "1erge, changes from trunk to your_branch: 6&11!'""
$e!lace 6&11!'" with the e'act command contents from ste! *.
4hew.
folding the branch back into trunk
5e", your_branch is done6 Now it has to become trunk, so ever"one will use it and see how
awesome it is.
-his onl" ha!!ens once !er branch.
1. /irst, follow ever" ste! in the !revious section %7u!dating the branch8& so that
your_branch is in s"nc with an" recent changes on trunk.
2. 1elete trunk com!letel":
svn ,e) svn://server.com/svn/repository/trunk
(. ove your_branch onto the old trunk location:
svn mv svn://server.com/svn/repository/branches/your_branch \
svn://server.com/svn/repository/trunk
*. $elocate "our working co!" back to trunk:
svn s(itch --re)ocate \
svn://server.com/svn/repository/branches/your_branch \
svn://server.com/svn/repository/trunk
0ll done.
svn branching best practices (in practice) snax http://blog.evanweaver.com/2007/08/15/svn-branching-best-practices-i...
2 z 2 24.1.2012 16:32

You might also like