Orphaned Branches in TFS - tfs

We have a trunk in TFS that everyone works off until we have a need to branch. Our last project was a large feature that required a branch. Now that the development has been completed and the changes have been merged back into the trunk. What should happen to the development branch?
Should I delete it? Mark it as read-only somehow? What about cloaking and locking?

You can make a branch read-only. You just need to remove the check-in/check-out permissions from the appropriate groups. Note that it doesn't look any different on first blush, but when you attempt to check out a file, you'll be prevented.
I always end up deleting the branch. It's "deleted" but there's nothing preventing you from undeleting it (which is different that destroying) or looking back at the code. It doesn't actually go anywhere unless you go through the effort of destroying it.
In addition, if you have a nice tool like Team Foundation Sidekicks, you can still see all of the branching history, even if it's been deleted.
You can, as #Ray says, just leave it, but if you do that over the course of a dozen or so branches, things become a bit unwieldy to manage. If the branch is dead, and you've merged the code into mainline, do you have any purpose for keeping it around aside from "just-in-case."
If so, just delete it and dig back through it only if you really have to.

Just leave it. :) You can delete the branch but it will still remain in the repository. It really is a decision that you and your team can make to follow your source control guidelines.
On a side note, there is no read-only option in TFS, you can only leave it, delete it or run the TFS destroy command to permanently remove the branch.

There is a Read access control permission. If you set Contributors to "Deny", it should override any "Not Set" or "Allow" permissions. You can set it in Source Control Explorer by right-clicking on the folder and going into Advanced | Security...

Related

Which TFS Permissions Need to be Denied to Prevent a Branch Appearing in the "Merge" Dialog?

Our TFS processes used to use a branch-per-revision technique. Although I've changed that now, we still have old branches from the "per release" days.
When I start a "Merge" from our "DEV" (main, trunk) branch, I still see all of the old release branches as possible merge targets. This is inconvenient.
Short of deleting the old branches, is there a set of permissions I can apply which will keep everyone (including me) from seeing those branches in the "Merge" dialog as targets?
You can deny read permissions on those branches in source control. After doing this, the branch will be shielded in TFS. You can do this in the VS(right click the branch-advanced-security) or using tf permission command
However in your situation, I will recommend you to delete the branch, since you want to applicable to everybody. Delete is the simplest solution, and you can undelete it if needed. Setting permissions are works well when preventing someone to access the source contorl folder. But not the best one in this case.

TFS without any branch

Do you really need a Branch to CheckIn / CheckOut Code in TFS i.e, just add files to a folder ?
What would be advantage to Branch in that case ?
You do not need a branch to check in and check out.
Branches however provide you with the ability to make changes to more thank one version of your code at once. Lets say that you have one folder at $/ProjectA/MyAwesomeApplication/Master. You can happily work away, checking in and releasing. At some point you find a bug in production that needs fixed immediately. However MASTER is well beyond what was last released and you don't want to deploy those changes yet.
You know which build is deployed and thus which changeset. You can branch MASTER at that changeset (the past) and create $/ProjectA/MyApplication/QuickFix. There you can fix that bug and ship, then merge back into MASTER and delete that branch.
Now obviously this is expensive and time consuming. A better way would to move forward and just ship what is in MASTER. If you have feature flags and good testing them you should be able to do that. There are however always those exceptions to that rule, and that's where branching comes in.
If you are using Git in TFS rather than TFVC the story is different.

Why does TFS allow a single changeset to affect multiple branches? If there isn't a very good reason, can this be prevented?

It has recently happened that a coworker, after completing some minor changes to the Stable branch of our solution, accidentally checked-in some of his unfinished work on the Development branch as well. TFS bundled it all up as a single changeset.
While the mistake was easily detected and fixed, I feel like I am missing something critical here. Why would TFS's "Pending changes" page allow you (and, worse, offer by default) to create a single changeset containing everything you've done on every branch?
It seems to me that a changeset should consist of changes to one and only one branch, so you can more effectively manage/merge/rollback them as necessary, without affecting other branches. If you have been working on multiple branches at the same time, upon checking-in it should ask you to insert multiple descriptions, and create multiple changesets as a result.
Assuming my reasoning is at least valid (if not necessarily universal), is there a way to configure TFS so that users may not check-in changes to more than one branch at a time?
EDIT: Failing that, I would appreciate a way to at least set the 'Pending Changes' page to put all changed files by default in the 'Excluded' section, so users will need to manually include them before checking in (which would help them notice any accidental changes).
Best practice: A developer can check in pending changes limited to a given folder/branch by right-clicking the folder, choosing "Check in pending changes". For that check-in action, the "Pending Changes" view will temporarily "exclude" any changes made outside of that folder/branch until you complete the check-in.
Can it be prevented: Per Microsoft, there is a premade Check-in Policy option known as "Enforce check-in to only contain files that are part of current solution". This may work for you, assuming you use "Solutions".
Why is this allowed: I suppose it's just how TFS was designed. I'd suspect it's to do with the treatment of branches as folders, and allowing check-in's across folders leaks into allowing check-in's across branches.
I can think of some scenario where this could be useful, like applying a critical fix on both release and main branches and merge is not an option.
What you can do to minimize the risk is to reduce the scope of developer workspaces as suggested by Jesse in Check-in each project separately?.

What to do with a branch after the merge with TFS

After merging a branch back to the "trunk" what do most people do with the branch. Just delete it? Move it to another area? Change it's permissions?
The concern we have is that developers who are away, and don't read their mail could come to work and continue working on the branch, after the merge has been done.
Once the branch is definitely dead then I like to delete them. You can always undelete something in TFS if necessary (Options, Source Control, Show Deleted Items). Dev's working in that area without realizing it may get some strange behaviour (i.e. files dissapearing when they do a Get Latest) however it get's them to figure out something has happened pretty quickly.
That said, sometimes it can take a while to ensure that the branch is definitely deceased in which case changing the permissions on the branch so that only a limited number of people can edit the files on that branch is a handy technique. You can have one person lock all the files in the branch with a check-out lock but I've not found that to work too well when freezing a branch - permissions seems to work better so that you do not have to have a bunch of pending changes (the locks) to manage for all the files in the branch and also you can have more than one person working on it while it is being frozen.
We delete branches, once we're sure the merge was successful.
We move them to an Archive folder. We should probbaly change permissions as well.

What's the best way to deal with dead branches in TFS?

In TFS, what is the best way to mark dead branches? Do you move your branch? Branch release it? Delete it? Rename it? What problems have you run into for each of these approaches? What are the good points?
It would be nice if there were a simple interface solution that would simply mark or filter the current view if a particular branch was tagged as dead. That way you wouldn't have to do something permanent like rename or delete a branch . . .
Deletion isn't permanent, so I'd go with this option.
You can then opt whether or not to view deleted items in SCE (Tools -> Options -> Source Control -> Visual Studio Team Foundation Server -> Show deleted items in the Source Control Explorer).
And you can choose to undelete the branches if necessary.
After merging back to the trunk we do delete them much easier than having to cloak them in workspaces, see Ian's about deletes not being permanent.
We move our dead branches to an archive area of the project.
Because the branches are cheap in
TFS, there is not a space concern.
Deletion can cause bizarre problems when someone attempts to add something new with the same name.
Moving them enables continued use of features like Annotate (a.k.a. blame), which allows drilling through branches to see a full history of changes.

Resources