Thursday, February 2, 2012

Migrating a shelveset from one branch to another

Are you working on an application development which follows code branching strategy in order to deliver timely product releases? If yes, then you might need to merge a shelveset from one branch to another. Here are the simple steps to do the same.

1. Visual Studio 2010
2. Team Foundation Server power tools 2011. Link To Download

Steps to follow:
TFS Power Tools provides the ability to migrate a shelveset, but with the limitation that you can use this feature only through command line.
1. Quick link to open Visual Studio command prompt is press Windows key and type "Command" in search box.

2. "tfpt unshelve" is the command provided by power tools for code migration and that's all you need to know. To get a brief overview about the command type "tfpt unshelve /?" in command prompt.

Quite simple, you just have to use the command as mentioned in usage. However, you need to take care of the source and target branch path. 

3. Simple Rule:
I'm assuming that both source and target branch are under the same folder say "Gulliver" here and branch hierarchy is "Gulliver/Code-branch-1", "Gulliver/Code-branch-2". You have created a shelveset in code-branch-1 and want to migrate it to code-branch-2. Also, your solution lies in Code-branch-1, Code-branch-2 folder.

Change your command prompt directory from default one to the both branch common folder, Gulliver here. Thereafter your command to migrate will be:

tfpt unshelve "<shelveset name>";<developername> /migrate /source:"<source branch solution path>" /target:"<target branch solution path>"

e.g. : tfpt unshelve "demo_shelveset";rkandhal /migrate /source:"$/Code-branch-1" /target:"$Code-branch-2/"

Note: Few imp points worth noting,
1. In above command $ in source/target path represents the root directory of your TFS repository. So take care of both paths considering their hierarchy in tfs.
2. You may receive an error entitled: "Unhandled exception has occured in a component in your application. The path 'adbcadsfasdf' contains the character ';'. Remove the ';' and try again." This issue happens because of wrong target  branch path. Provide the target branch path somewhat similar to "$/branch-2/"  - no colon in the end.

Thats it, you are done. On command execution, if your code is password protected, then you will be prompted for TFS password then Unshelve dialog will open and you're required to select the shelveset which you want to merge. There after auto-merge dialog prompts up and in case you have not provide the correct target branch path, resolution will results to an error otherwise your code changes will be merged to target branch. Here is the snapshot of command output:

Notice that for each file there is a result status in command window.


  1. Thanks for a nice article. Trying this out, however, no rewriting is taking place. Even though I had specified /merge, /source and /target, all my shelved changes still end up in my source branch.

    1. Please share a brief about your source/target directory details and the command you're writing. There must be some issue in that syntax. (Even first time when I tried this, it din't work)

    2. The not rewriting happened to me too. I happened to be using tfpt from a regular command prompt instead of a VS command prompt. I was also using a local workspace. I changed the work space to a server based workspace and used a VS command prompt and everything worked as expected.

    3. I will look further into it soon.

  2. What if there are more than one solution involved in the Shelfset? Your instructions say the source and target paths should point to the Solution.

    1. Well, I've not tried this but will surely do. Regarding source and target paths in that case try providing them as "$/RootFolder/Code-branch1", "$/RootFolder/Code-branch2". Assuming your multiple solutions lies under Code-branch1 directory and you want to move them under Code-branch2 directory. I'm not sure whether it's the perfect answer but thanks for a very good and genuine point. I'll surely look into it.