How do I create a branch?
Solution 1
Branching in Subversion is facilitated by a very very light and efficient copying facility.
Branching and tagging are effectively the same. Just copy a whole folder in the repository to somewhere else in the repository using the svn copy
command.
Basically this means that it is by convention what copying a folder means - whether it be a backup, tag, branch or whatever. Depending upon how you want to think about things (normally depending upon which SCM tool you have used in the past) you need to set up a folder structure within your repository to support your style.
Common styles are to have a bunch of folders at the top of your repository called tags
, branches
, trunk
, etc. - that allows you to copy your whole trunk
(or sub-sets) into the tags
and/or branches
folders. If you have more than one project you might want to replicate this kind of structure under each project:
It can take a while to get used to the concept - but it works - just make sure you (and your team) are clear on the conventions that you are going to use. It is also a good idea to have a good naming convention - something that tells you why the branch/tag was made and whether it is still appropriate - consider ways of archiving branches that are obsolete.
Solution 2
Create a new branch using the svn copy
command as follows:
$ svn copy svn+ssh://host.example.com/repos/project/trunk \
svn+ssh://host.example.com/repos/project/branches/NAME_OF_BRANCH \
-m "Creating a branch of project"
Solution 3
If you're repo is available via https, you can use this command to branch ...
svn copy https://host.example.com/repos/project/trunk \
https://host.example.com/repos/project/branches/branch-name \
-m "Creating a branch of project"
Solution 4
svn cp /trunk/ /branch/NEW_Branch
If you have some local changes in trunk then use Rsync
to sync changes
rsync -r -v -p --exclude ".svn" /trunk/ /branch/NEW_Branch
Solution 5
Suppose you want to create a branch from a trunk name (as "TEST") then use:
svn cp -m "CREATE BRANCH TEST" $svn_url/trunk $svn_url/branches/TEST
sparkes
General hacker from the UK who is rapidly getting fed up of the sort of tossers attracted to SO beta. It's a crying shame that something with so much potential is going to end up like Slashdot. Joel, Jeff, guys while it's the crowd that can make this place that's what's going to kill it too.
Updated on August 03, 2022Comments
-
sparkes almost 2 years
How do I create a branch in SVN?
-
WhyNotHugo about 14 years"svn copy" has the advantage that it will retain history previous to the branching. Manually copying to another directory won't.
-
Anonigan over 11 yearsNext use
svn switch svn+ssh://host.example.com/repos/project/branches/NAME_OF_BRANCH .
(if you want to switch current checkout to new branch) orsvn checkout svn+ssh://host.example.com/repos/project/branches/NAME_OF_BRANCH
(if you want to have new branch in seperate directory) to start working on newly created branch. -
Anonigan over 11 yearsNote: in some cases you would need to use
--parents
option withsvn copy
! -
sleske about 11 yearsAlso note that it's usually a bad idea to tag or branch subdirectories of "trunk". This makes it difficult to keep track of which subdirectory was branched, and most tools will get confused by these branches (e.g. switching branches will mean the directory structure of the WC changes, which will confuse IDEs and build tools). Just always branch "trunk".
-
Aviel Gross over 10 yearsfor some reason I used this cmd and it didn;t work, but when i changed the svn+ssh to just https it did work. Did I do anything wrong? what is the meaning of svn+ssh? Thanks!
-
chim about 9 yearsYou can also use ^ in place of the Repository Root
-
Silvio Troia about 9 yearsyou have to create first a new directory in your branch -> svn mkdir host.example.com/repos/project/branches/NAME_OF_BRANCH -m "make the branches directory to hold all the branches"
-
littlebroccoli over 8 yearsThere is no requirement to use
rsync
in this way.svn cp
will also copy any local changes. -
Parag Bafna over 8 years@KevinPanko It won't copy uncommitted changes.
-
littlebroccoli over 8 yearsIt does, confirmed with svn, version 1.8.5
-
oligofren about 8 yearsI am wondering about this. This seems like the easiest option, and AFAI remember, this is what I did when I was working with SVN 3 years ago. But what is the difference between this and the ones working directly with the server urls?
-
Hi-Angel almost 8 yearsIf I omit the
-m
option, it says likesvn: E155010: Path '/home/constantine/someDirectory/svn+ssh:https:/myhost.com/svn/dir1/dir2/trunk/dir3/dir4/dir5' does not exist
. With-m
it sayssvn: E205009: Local, non-commit operations do not take a log message or revision properties
. (I replaced the addresses, but they do exist, except, ofc, the new branch directory, and the whole path+url that SVN for some reason merged in the error). -
Hi-Angel almost 8 yearsOkay, the answer below worked. Since, I guess,
svn cp
==svn copy
, the partsvn+ssh
in this answer is wrong, it doesn't work (triggers the above error ↑ ). -
Walty Yeung about 6 years@Will Actually
svn cp
uses cheap copies, it does not copy the actual files during the branching. See svnbook.red-bean.com/en/1.1/ch04s02.html -
John Hamilton almost 5 years@KevinPanko Do you know whether it also copies newly created files?