Team Foundation Version Control provides you with an option to prune a branch from somewhere in a given hierarchy and graft it on elsewhere in the same hierarchy. Consider using this approach if the branch structure you put in place is incorrectly set up or has stopped working as you have scaled up. In this recipe, you'll learn how to reparent a branch in TFVC.
Note
The movement of the reparented branch is logical not physical and can be done without stopping developers from working. However, it's a good idea to get developers to shelve changes. You should also endeavor to make the new parent as close in content to the old parent to avoid merge conflicts.
Getting ready
In order to reparent a branch, your user account needs to have the Manage branch permission. The project administrator group and project collection administrator group already grant this permission; however, this permission can be set to allow directly on individual users and groups:
The Manage branch permission allows you to perform the following:
Convert a folder into a branch
Execute the following actions
Edit the branch properties
Reparent the branch
Convert the branch into a folder
In your TFVC project, create a branching structure as illustrated in the figure on the left:
The scenario we'll be working through in this recipe, as illustrated in the figure on the left, is the Development Team releases from the Main branch; Release 1.1 was branched from Release 1. As illustrated in the figure on the right, the Team wants to move Release 1.1 directly under the Main branch, so changes don't need to go through Release 1 to be merged to Release 1.1.
To reparent the branch Release 1.1 from Release 1 to Main, a relationship needs to be established between the two branches. This can only be done by performing a baseless merge between the two branches. Refer to the Performing a baseless merge between sibling branches in TFVC recipe to learn how to perform a baseless merge.
This recipe assumes that a merge relationship has been established between the Main and Release 1.1 branch. In the preceding figure, the dashed line represents a relationship between the two branches.
How to do it…
Navigate to Source Control Explorer, right-click on the branch Release 1.1 and choose Reparent... from the Branching and Merging submenu:
In the Reparent window, you'll see a list of all branches that have a direct or indirect relationship with Release 1.1. Select Main and click on Reparent. Selecting No parent will make Release 1.1 an independent branch:
The reparent operation takes place on the server. You will not see any pending changes as a result of the reparent operation. The branch hierarchy after the reparent operation is as follows:
How it works…
Once the reparent operation has been completed, you can view the updated branch hierarchy by right-clicking on the Release1.1 branch and choosing Properties from under the Advanced submenu:
Click on the Relationships tab from the left menu to see the branch relationships.