7

I am pretty new to TFS and source control. I unable to understand the advantage of branching. Since i can do the same stuff by creating 2 folder main and development, when I am done with development.I can merge the code using any diff tool with the main branch.

Then whats the point of having branches ? I know there must a huge advantage but i am unable to understand.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
Gainster
  • 5,481
  • 19
  • 61
  • 90

2 Answers2

32

(UPDATE: TFS now supports git for version control so the rest of this answer no longer applies)

I would google branch-per-feature.

The main advantage of branching is that you can work on a feature and not be interrupted by anyone else's work. When you are ready, you can merge and see if many features work well together or not. This is usually done as the feature is developed but for small features can be done once the feature is complete.

The advantage is that you have a clear history of what you did to implement something. Without branches, you would have a whole lot of commits mixed together with other features' commits. If QA does not pass a certain feature, you have your work cut out for you to put together another build using just the commits for the other features. The other alternative is to try and fix your feature so that QA passes. This may not be doable on a Friday afternoon.

Feature toggles are another way to omit work but this increases the complexity of code and the toggles may themselves have bugs in them. This is something to be very weary of and see how this became an "acceptable" work-around.

Branches are also used to track changes to multiple versions of releases. Products that are consumed by multiple customers may be in a situation that one set of customers is using 1.0 of the product while others are already on 2.0. If you support both, you should track changes to each by branches that are designated to them. The previous points still apply to developing for these branches.

Having said that, TFS is not ideal at branch-per-feature for a number of reasons. The biggest is that it does not support 3-way merges - it only has what is called a baseless merge. The way history is tracked, TFS cannot show you a common ancestor between the feature branch and where you are trying to merge it to. This leaves you potentially solving a lot of conflicts. In general, a lot of people that use TFS shy away from branching for this reason.

3-way merges are great because they will show you what the common ancestor is, what your changes are and what the changes in the other branch are. This will allow you to make a very educated decision on how to resolve a conflict.

If you have to use TFS, I would suggest using git-tfs to be able to take advantage of 3-way merges and many other features. Some of them include: rerere, rebasing, disconnected model, local history, bisect, and many many more.

Rebase is very useful as it allows you to alter a feature to be based off of another starting point, omit commits, squash commits together, split commits, etc. Once ready you can them merge into an integration or release branch, depending on the workflow you decide upon.

Mercurial is also another one that may be easier to use, but will not be as powerful in the long run.

If you have the opportunity, I would highly recommend moving away from TFS for source control due to a lot of limitations when compared to modern day DVCS.

Here is a nice set of guidelines to follow if you want to effectively manage branching/merging:

http://dymitruk.com/blog/2012/02/05/branch-per-feature/

Hope this helps.

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
  • 6
    -1: he asked about TFS. He didn't ask for a rant against TFS. This is also not "the main advantage of branching". That might be the case for small groups of developers, but not in a commercial or Enterprise project. – John Saunders Jun 01 '11 at 23:52
  • 11
    FWIW I think the info is fair, if unprompted. Many times unprompted info is still very appreciated. – sehe Jun 02 '11 at 00:18
  • 11
    This is about branching. He happens to be using tfs. The truth is sometimes unpleasant. – Adam Dymitruk Jun 02 '11 at 06:16
  • 1
    Either way, not having 3 way merging is going to hurt - enterprise or not. True, branches can be kept for supporting back versions, patches, hot fixes, localization, etc. The idea of branch understanding is learned well whensomething with a quick turnaround time like bpf is examined. This is why I suggested it. – Adam Dymitruk Jun 02 '11 at 06:31
  • 5
    Siding with adymitruk on this one. This is good, it dives into branching but also offers sound advice on issues with TFS. No VCS is without its problems (even DVCS). If you don't know the weaknesses of something you are using and only the strengths, you are setting yourself up for some heartache. – ferventcoder Jun 02 '11 at 18:08
  • 2
    WRONG! TfS saves the common ancestor - just do a get version by date! You can label them if don't remember dates. You can also use branching to create the common ancestor yourself. Yes, these are somewhat hacks, but come on, they are LITERALLY 1000x easier than switching source control systems (unless you have very small # of projects or developers). Good grief! – FastAl Jun 02 '11 at 18:15
  • 2
    sorry, not worth it when in the end you end up with a baseless merge, no local history and all other issues. Totally worth switching. Many people are doing it. Search twitter for #tfs OR #git OR #mercurial OR #svn and see what's happening there. – Adam Dymitruk Jun 02 '11 at 18:18
  • @AdamDymitruk: TFS absolutely performs a three-way merge (if there exists a common ancestor between the two branches). Why do you believe it doesn't? – Edward Thomson Feb 16 '13 at 00:36
  • it did not before. At least if it wasn't a direct descendent. It was common knowledge that you did not have a base version when doing merges in TFS. – Adam Dymitruk Feb 20 '13 at 20:05
4

There is a lot of information to read through, but there is TFS Branching Guidance located here if it helps at all - http://tfsbranchingguideiii.codeplex.com/

Brian Webster
  • 30,033
  • 48
  • 152
  • 225
Rob Gibbens
  • 1,122
  • 1
  • 8
  • 24
  • 2
    You can also look at a [branch per story pattern](http://www.richard-banks.org/2011/02/branch-per-story-pattern-and-tfs.html) and how to do [in-place branch switching with TFS](http://www.richard-banks.org/2011/03/how-to-in-place-branch-switching-with.html) – Richard Banks Jul 08 '11 at 01:04