<p>Suppose you're developing a software product that has periodic releases. What are the best practices with regard to branching and merging? Slicing off periodic release branches to the public (or whomever your customer is) and then continuing development on the trunk, or considering the trunk the stable version, tagging it as a release periodically, and doing your experimental work in branches. What do folks think is the trunk considered "gold" or considered a "sand box"?</p>

[{'answer_id': 35648, 'author': '17 of 26', 'author_id': 2284, 'author_profile': 'https://Stackoverflow.com/users/2284', 'pm_score': 1, 'selected': False, 'text': "<p>The trunk is generally the main development line.  </p>\n\n<p>Releases are branched off and often times experimental or major work is done on branches then merged back to the trunk when it's ready to be integrated with the main development line.</p>\n"}, {'answer_id': 35650, 'author': 'Matt Dillard', 'author_id': 863, 'author_profile': 'https://Stackoverflow.com/users/863', 'pm_score': 5, 'selected': False, 'text': '<p>I tend to take the "release branch" approach.  The trunk is volatile.  Once release time approaches, I\'d make a release branch, which I would treat more cautiously.  When that\'s finally done, I\'d label/tag the state of the repository so I\'d know the "official" released version.</p>\n\n<p>I understand there are other ways to do it - this is just the way I\'ve done it in the past.</p>\n'}, {'answer_id': 35652, 'author': 'Jon Limjap', 'author_id': 372, 'author_profile': 'https://Stackoverflow.com/users/372', 'pm_score': 3, 'selected': False, 'text': '<p>I think your second approach (e.g., tagging releases and doing experimental stuff in branches, considering the trunk stable) is the best approach. </p>\n\n<p>It should be clear that branches inherit all the bugs of a system at the point in time where it is branched: if fixes are applied to a trunk, you will have to go one by one to all branches if you maintain branches as a sort of release cycle terminator. If you have already had 20 releases and you discovered a bug that goes as far back as the first one, you\'ll have to reapply your fix 20 times.</p>\n\n<p>Branches are supposed to be the real sand boxes, although the trunk will have to play this role as well: tags will indicate whether the code is "gold" at that point in time, suitable for release.</p>\n'}, {'answer_id': 35653, 'author': 'Jim', 'author_id': 1208, 'author_profile': 'https://Stackoverflow.com/users/1208', 'pm_score': 1, 'selected': False, 'text': "<p>The trunk should generally be your main development source.  Otherwise you will spend a lot of time merging in new features.  I've seen it done the other way and it usually leads to a lot of last minute integration headaches.</p>\n\n<p>We label our releases so we can quickly respond to production emergencies without distribing active development.</p>\n"}, {'answer_id': 35654, 'author': 'Brian Stewart', 'author_id': 3114, 'author_profile': 'https://Stackoverflow.com/users/3114', 'pm_score': 3, 'selected': False, 'text': '<p>We develop on the trunk unless the changes are too major, destabilizing, or we are nearing a major release of one of our products, in which case we create a temporary branch. We also create a permanent branch for every individual product release. I found Microsoft\'s document on <a href="http://www.codeplex.com/BranchingGuidance/Wiki/View.aspx?title=Guidance%20for%20Structuring%20Team%20Projects" rel="noreferrer">Branching Guidance</a> quite helpful. Eric Sink\'s <a href="http://www.ericsink.com/scm/scm_branches.html" rel="noreferrer">tutorial on branching</a> is also interesting, and points out that what works for Microsoft may be too heavy for some of the rest of us. It was in our case, we actually use the approach Eric says his team does.  </p>\n'}, {'answer_id': 35655, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>Attempting to manage maintenance of current production code in line with new development is problematic at best. In order to mitigate those problems code should branch into a maintenance line once testing efforts have completed and the code is ready for delivery. Additionally, the mainline should branch to assist in release stabilization, to contain experimental development efforts, or to house any development efforts whose lifecycle extends across multiple releases.</p>\n\n<p>A non-maintenance branch should be created only when there is the likelihood (or certainty) of collisions among the code that would be difficult to manage any other way. If the branch does not solve a logistical problem, it will create one.</p>\n\n<p>Normal release development occurs in the mainline. Developers check into and out of the mainline for normal release work. Development work for patches to current Production code should be in the branch for that release and then merged with the mainline once the patch has passed testing and is deployed. Work in non-maintenance branches should be coordinated on a case-by-case basis. </p>\n'}, {'answer_id': 35657, 'author': 'cpm', 'author_id': 3674, 'author_profile': 'https://Stackoverflow.com/users/3674', 'pm_score': 1, 'selected': False, 'text': '<p>For me, it depends on the software I\'m using. </p>\n\n<p>Under CVS, I would just work in "trunk" and never tag/branch, because it was really painful to do otherwise.</p>\n\n<p>In SVN, I would do my "bleeding edge" stuff in trunk, but when it was time to do a server push get tagged appropriately.</p>\n\n<p>I recently switching to git. Now I find that I never work in trunk. Instead I use a named "new-featurename" sandbox branch and then merge into a fixed "current-production" branch. Now that I think about it, I really should be making "release-VERSIONNUMBER" branches before merging back into "current-production" so I can go back to older stable versions...</p>\n'}, {'answer_id': 35661, 'author': 'Josh Segall', 'author_id': 2659, 'author_profile': 'https://Stackoverflow.com/users/2659', 'pm_score': 3, 'selected': False, 'text': '<p>It depends on your situations.  We use Perforce and have typically have several lines of development.  The trunk is considered "gold" and all development happens on branches that get merged back to the mainline when they are stable enough to integrate.  This allows rejection of features that don\'t make the cut and can provide solid incremental capability over time that independent projects/features can pick up.</p>\n\n<p>There is integration cost to the merging and catching up to new features rolled into the trunk, but you\'re going to suffer this pain anyway.  Having everyone develop on the trunk together can lead to a wild west situation, while branching allows you to scale and choose the points at which you\'d like to take the bitter integration pills.  We\'re currently scaled to over a hundred developers on a dozen projects, each with multiple releases using the same core components, and it works pretty well.</p>\n\n<p>The beauty of this is that you can do this recursively: a big feature branch can be its own trunk with other branches coming off if it.  Also, final releases get a new branch to give you a place to do stable maintenance.</p>\n'}, {'answer_id': 35663, 'author': 'DevelopingChris', 'author_id': 1220, 'author_profile': 'https://Stackoverflow.com/users/1220', 'pm_score': 2, 'selected': False, 'text': '<p>If you are gonna be working through a release cycle, big feature, you get marooned to a branch. Otherwise we work in trunk, and branch for every production release at the moment we build. </p>\n\n<p>Previous production builds are moved at that time to old_production_ and current prod release is always just production. All our build server knows about production is how to deploy the production branch, and we kick that build off with a force trigger.</p>\n'}, {'answer_id': 35674, 'author': 'Harpreet', 'author_id': 855, 'author_profile': 'https://Stackoverflow.com/users/855', 'pm_score': 2, 'selected': False, 'text': '<p>It depends on the size of your development effort.  Multiple teams working in parallel won\'t be able to work effectively all on the same code (trunk).  If you have just a small group of people working and your main concern is cutting a branch so you can continue to work while going back to the branch for making bug-fixes to the current production code that would work. This is a trivial use of branching and not too burdensome.</p>\n\n<p>If you have a lots of parallel development you\'ll want to have branches for each of the efforts but that\'ll also require more discipline:  Making sure your branches are tested and ready to merge back.  Scheduling merges so two groups aren\'t trying to merge at the same time etc.  </p>\n\n<p>Some branches are under development for so long that you have to permit merges  from the trunk to the branch in order to reduce the number of surprises when finally merging back to the trunk.</p>\n\n<p>You will have to experiment if you have a large group of developers and get a feel for what works in your situation.  Here is a page from Microsoft that may be somewhat useful: <a href="http://msdn.microsoft.com/en-us/library/aa730834(VS.80).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/aa730834(VS.80).aspx</a></p>\n'}, {'answer_id': 35690, 'author': 'Brian R. Bondy', 'author_id': 3153, 'author_profile': 'https://Stackoverflow.com/users/3153', 'pm_score': 8, 'selected': True, 'text': "<p>I have tried both methods with a large commercial application.  </p>\n\n<p>The answer to which method is better is highly dependent on your exact situation, but I will write what my overall experience has shown so far. </p>\n\n<p><strong>The better method overall (in my experience): The trunk should be always stable.</strong></p>\n\n<p>Here are some guidelines and benefits of this method:</p>\n\n<ul>\n<li>Code each task (or related set of tasks) in its own branch, then you will have the flexibility of when you would like to merge these tasks and perform a release.  </li>\n<li>QA should be done on each branch before it is merged to the trunk. </li>\n<li>By doing QA on each individual branch, you will know exactly what caused the bug easier.</li>\n<li>This solution scales to any number of developers.  </li>\n<li>This method works since branching is an almost instant operation in SVN.</li>\n<li>Tag each release that you perform.</li>\n<li>You can develop features that you don't plan to release for a while and decide exactly when to merge them.  </li>\n<li>For all work you do, you can have the benefit of committing your code.  If you work out of the trunk only, you will probably keep your code uncommitted a lot, and hence unprotected and without automatic history. </li>\n</ul>\n\n<p>If you try to do the opposite and do all your development in the trunk you'll have the following issues:</p>\n\n<ul>\n<li>Constant build problems for daily builds</li>\n<li>Productivity loss when a a developer commits a problem for all other people on the project</li>\n<li>Longer release cycles, because you need to finally get a stable version</li>\n<li>Less stable releases</li>\n</ul>\n\n<p>You simply will not have the flexibility that you need if you try to keep a branch stable and the trunk as the development sandbox.  The reason is that you can't pick and chose from the trunk what you want to put in that stable release.  It would already be all mixed in together in the trunk.</p>\n\n<p>The one case in particular that I would say to do all development in the trunk, is when you are starting a new project.  There may be other cases too depending on your situation.</p>\n\n<hr>\n\n<p>By the way distributed version control systems provide much more flexibility and I highly recommend switching to either hg or git.</p>\n"}, {'answer_id': 35899, 'author': 'Rob Wells', 'author_id': 2974, 'author_profile': 'https://Stackoverflow.com/users/2974', 'pm_score': 6, 'selected': False, 'text': '<p>I\'ve worked with both techniques and I would say that developing on the trunk and branching off stable points as releases is the best way to go.</p>\n\n<p>Those people above who object saying that you\'ll have:</p>\n\n<blockquote>\n  <ul>\n  <li>Constant build problems for daily builds </li>\n  <li>Productivity loss when a a developer commits a problem for all\n  other people on the project</li>\n  </ul>\n</blockquote>\n\n<p>have probably not used continuous integration techniques.</p>\n\n<p>It\'s true that if you don\'t perform several test builds during the day, say once every hour or so, will leave themselves open to these problems which will quickly strangle the pace of development.</p>\n\n<p>Doing several test builds during the day quickly folds in updates to the main code base so that other\'s can use it and also alerts you during the day if someone has broken the build so that they can fix it before going home.</p>\n\n<p>As pointed out, only finding out about a broken build when the nightly build for running the regression tests fails is sheer folly and will quickly slow things down.</p>\n\n<p>Have a read of Martin Fowler\'s paper on <a href="http://martinfowler.com/articles/continuousIntegration.html" rel="noreferrer">Continuous Integration</a>. We rolled our own such system for a major project (3,000kSLOC) in about 2,000 lines of Posix sh.</p>\n'}, {'answer_id': 47118, 'author': 'Lou', 'author_id': 4341, 'author_profile': 'https://Stackoverflow.com/users/4341', 'pm_score': 2, 'selected': False, 'text': "<p>We follow the trunk=current development stream, branch=release(s) approach. On release to the customer we branch the trunk and just keep the trunk rolling forward. You'll need to make a decision on how many releases you're prepared to support. The more you support the more merging you'll be doing on bug fixes. We try and keep our customers on no more than 2 releases behind the trunk. (Eg. Dev = 1.3, supported releases 1.2 and 1.1).</p>\n"}, {'answer_id': 79659, 'author': 'Travis B. Hartwell', 'author_id': 10873, 'author_profile': 'https://Stackoverflow.com/users/10873', 'pm_score': 4, 'selected': False, 'text': '<p>A good reference on a development process that keeps trunk stable and does all work in branches is Divmod\'s <a href="https://twistedmatrix.com/trac/wiki/UltimateQualityDevelopmentSystem" rel="nofollow noreferrer">Ultimate Quality Development System</a>.  A quick summary:</p>\n\n<ul>\n<li>All work done must have a ticket associated with it</li>\n<li>A new branch is created for each ticket where the work for that ticket is done</li>\n<li>Changes from that branch are not merged back into the mainline trunk without being reviewed by another project member</li>\n</ul>\n\n<p>They use SVN for this, but this could easily be done with any of the distributed version control systems.</p>\n'}, {'answer_id': 107785, 'author': 'adriaanp', 'author_id': 12230, 'author_profile': 'https://Stackoverflow.com/users/12230', 'pm_score': 2, 'selected': False, 'text': '<p>We are using the trunk for main development and branch for releases maintenance work. It works nice. But then branches should only be used for bug fixes, no major changes, especially on database side, we have a rule that only a schema change can happen on the main trunk and never in the branch.</p>\n'}, {'answer_id': 145379, 'author': 'Andrew Edgecombe', 'author_id': 11694, 'author_profile': 'https://Stackoverflow.com/users/11694', 'pm_score': 4, 'selected': False, 'text': "<p>Both.</p>\n\n<p>The trunk is used for the majority of development. But it's expected that best efforts will be made to ensure that any check-in to the trunk won't break it. (partially verified by an automated build and test system)</p>\n\n<p>Releases are maintained in their own directory, with only bug fixes being made on them (and then merged into trunk).</p>\n\n<p>Any new feature that is going to leave the trunk in an unstable or non-working state is done in it's own separate branch and then merged into the trunk up on completion.</p>\n"}, {'answer_id': 1897008, 'author': 'one eyed dev', 'author_id': 230741, 'author_profile': 'https://Stackoverflow.com/users/230741', 'pm_score': 0, 'selected': False, 'text': "<p>There's no one-size-fits-all answer for the subversion convention question IMHO.</p>\n\n<p>It really depends on the dynamics of the project and company using it. In a very fast-paced environment, when a release might happen as often as every few days, if you try to religiously tag and branch, you'll end up with an unmanageable repository. In such an environment, the branch-when-needed approach would create a much more maintainable environment.</p>\n\n<p>Also - in my experience it is extremely easy, from a pure administrative standpoint, to switch between svn methodologies when you choose to.</p>\n\n<p>The two approaches I've known to work best are the branch-when-needed, and the branch-each-task. These are, of course, sort of the exact opposite of one another. Like I said - it's all about the project dynamics.</p>\n"}, {'answer_id': 2451750, 'author': 'bo bo', 'author_id': 67706, 'author_profile': 'https://Stackoverflow.com/users/67706', 'pm_score': 1, 'selected': False, 'text': '<p>It really depends on how well your organization/team manages versions and which SCM you use. </p>\n\n<ul>\n<li>If what\'s next(in the next release) can be easily planned, you are better off with developing in the trunk. Managing branches takes more time and resources. But if next can\'t be planned easily(happens all the time in bigger organizations), you would probably end up cherry picking commits(hundreds/thousands) rather than branches(severals or tens). </li>\n<li>With Git or Mercurial, managing branches is much easier than cvs and subversion. I would go for the stable trunk/topic branches methodlogy. This is what the git.git team using. read:<a href="http://www.kernel.org/pub/software/scm/git/docs/gitworkflows.html" rel="nofollow noreferrer">http://www.kernel.org/pub/software/scm/git/docs/gitworkflows.html</a></li>\n<li>With Subversion, I first applied the develop-in-the-trunk methodlogy. There was quite some work when it came to release date because everytime I had to cherry pick commits(my company is no good at planning). Now I am sort of expert in Subversion and know quite well about manaing branches in Subversion, so I am moving towards the stable trunk/topic branches methodlogy. It works much better than before. Now I am trying the way how git.git team works, although we will probably stick with Subversion. </li>\n</ul>\n'}, {'answer_id': 2452028, 'author': 'Pascal Thivent', 'author_id': 70604, 'author_profile': 'https://Stackoverflow.com/users/70604', 'pm_score': 4, 'selected': False, 'text': '<p>I like and use the approach described by Henrik Kniberg in <a href="https://www.infoq.com/articles/agile-version-control/" rel="nofollow noreferrer"><strong>Version Control for Multiple Agile Teams</strong></a>. Henrik did a great job at explaining <em>how to handle version control in an agile environment with multiple teams</em> (works for single team in traditional environments too) and there is no point at paraphrasing him so I\'ll just post the "cheat sheet" (which is self explaining) below:</p>\n\n<p><a href="https://i.stack.imgur.com/6zJdG.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6zJdG.gif" alt="alt text"></a>\n<a href="https://i.stack.imgur.com/K9DNg.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/K9DNg.gif" alt="alt text"></a></p>\n\n<p>I like it because:</p>\n\n<ul>\n<li>It is simple: you can get it from the picture.</li>\n<li>It works (and scales) well without too much merge and conflict troubles.</li>\n<li>You can release "working software" at any time (in the spirit of agile).</li>\n</ul>\n\n<p>And just in case it wasn\'t explicit enough: development is done in "work branch(es)", the trunk is used for DONE (releasable) code. Check <a href="https://www.infoq.com/articles/agile-version-control/" rel="nofollow noreferrer"><strong>Version Control for Multiple Agile Teams</strong></a> for all the details. </p>\n'}, {'answer_id': 2513637, 'author': 'Kevin Crowell', 'author_id': 81193, 'author_profile': 'https://Stackoverflow.com/users/81193', 'pm_score': 1, 'selected': False, 'text': '<p>Here is the SVN design that I prefer:</p>\n\n<ul>\n<li>root\n\n<ul>\n<li>development\n\n<ul>\n<li>branches\n\n<ul>\n<li>feature1</li>\n<li>feature2</li>\n<li>...</li>\n</ul></li>\n<li>trunk</li>\n</ul></li>\n<li>beta\n\n<ul>\n<li>tags</li>\n<li>trunk</li>\n</ul></li>\n<li>release\n\n<ul>\n<li>tags</li>\n<li>trunk</li>\n</ul></li>\n</ul></li>\n</ul>\n\n<p>All work is done from development/trunk, except for major features that require its own branch. After work is tested against development/trunk, we merge tested issues into beta/trunk. If necessary, code is tested against the beta server. When we are ready to roll some changes out, we just merge appropriate revisions into release/trunk and deploy.</p>\n\n<p>Tags can be made in the beta branch or the release branch so we can keep track of specific release for both beta and release.</p>\n\n<p>This design allows for a lot of flexibility. It also makes it easy for us to leave revisions in beta/trunk while merging others to release/trunk if some revisions did not pass tests in beta.</p>\n'}]
['https://Stackoverflow.com/questions/35646', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/577/']