Introduction
This post assumes that you simply want to delete (retire) a branch and leave the workspace it belongs to as an active workspace. Workspaces can be removed within the TFS explorer unlike branches which have to be removed using the “tf” commands at the comand prompt. Deleting a branch is not the ultimate end to the branch, it is recoverable as we see later.
Deleting a branch in TFS
Start .Net 2005 command prompt:-
In XP, Start –> All Programs –> Visual Studio 2005 –> Visual Studio Tools –> Visual Studio 2005 Command Prompt
Ensure there is a workspace set up for the branch you want to delete and that a version of the branch has been fetched from TFS onto the local disk within the folder pointed to by the workspace.
In command prompt, change directory to the parent of the branch to be deleted. For example, if my workspace at the root level points to c:\projects and I have a branch called “TestMain” beneath it (c:\projects\TestMain) then do the following:-
> cd c:\projects
Then type:-
> tf delete /lock:checkout /recursive TestMain
You should see some confirmation messages about what has been deleted. What has happened here is that the workspace on disk has been deleted but the deletion itself still hasn’t happened on the TFS server. This will need to be reflected in TFS, so switching to the Team Explorer TFS client, quickly “Refresh” the screen and you should see the pending changes (deletions to be applied on the TFS server) as a red tick against the branch.
Check-in these changes and the branch is now retired!
Undeleting a branch in TFS
Fear not though, if you made a blunder and need to get the branch back, it hasn’t really gone! The history of what has happened with the branch is still there in TFS and it is possible to “undelete” the branch as follows:-
Do the same steps as before except that you need to replace the “tf delete” command with:-
> tf undelete /lock:checkout /recursive TestMain
You need to have deleted the branch using the “tf delete” command in TFS and have checked in the changes to commit the deletion to the TFS server prior to trying “undelete”, otherwise you will get a message similar to:-
“No matching deleted items found in <workspace path>“
That’s it.
Filed under: TFS


