Posted 30 July 2015 12:00 AM by Sergio Gisbert Ribes, Web Developer @ ClearPeople
Here at ClearPeople, we have decided recently to move all our source code projects from TFS 2010 on premise to Visual Studio Online. At the same time, we are reviewing and updating our source control workflow, so we decided to switch to Git as our Version Control System for all the new and already existing projects.
So we started an internal project called “Code migration from TFS TFVC to VSO Git”.
We’ll be focusing mostly on the code migration, as keeping the projects history was a key goal for the migration.
Regarding all the work items and relationships between them, there is some additional information out there, like https://www.microsoft.com/en-gb/developers/articles/week02mar2014/migrating-a-tfs-tfvc-based-team-project-to-a-git-team-project-retaining-as-much-source-and-work-item-history-as-possible/, but we finally decided to focus mainly on code, as moving the work items was not working in our scenario, where we have some custom templates for the TFS processes workflows.
As a starting point, we used the recommendations from http://hmemcpy.com/2014/06/migrating-from-tfs-to-git-to-visual-studio-online-the-survival-guide/, and based on them, we got a nice batch script that allowed us to move smoothly all our projects to VSO.
- Install Git-Tfs tool: https://github.com/git-tfs/git-tfs, and make sure it’s in the PATH
- Only branches can be migrated to Git, so we’d need to do different actions in the target project in TFS if needed https://github.com/git-tfs/git-tfs/blob/master/doc/Tfs-has-no-branches.md
1.3 Batch file
Our batch file looks like this:
if -%1-==-- echo TFS Project not provided & GOTO usage
if -%2-==-- echo Local destination folder not provided & GOTO usage
if -%3-==-- echo Remote Project name not provided & GOTO usage
if -%4-==-- echo Remote repository name not provided & GOTO usage
echo Usage: git-migrate [TFS Repo] [Destination Folder] [Remote Project] [Remote Repo]
echo Migration TFS project "%repo%" to VS Online project "%remoteProject%" into repo "%remoteRepo%"
set remoteProject=!remoteProject: =%%20!
set remoteRepo=!remoteRepo: =%%20!
git tfs clone %localRepo% %repo% %folder%
git remote add origin "%remote%/%remoteProject%/_git/%remoteRepo%"
@ECHO ONgit push -u origin –all
Make sure you edit localRepo and remote variables and set your own urls and save it to a bat file, like git-migrate.bat.
1.3.1 Batch file usage
The usage of the file will be like this:
C:\Git>git-migrate.bat <local tfs project> <local folder> <VSO Project Name> <VSO Git Repo name>
- <local tfs project>: is the name of the local project on TFS. Be careful with the spaces in the names, to use quotes if needed, like $"/tfs project name/src".
- <local folder>: This is the local folder where the project will be cloned from TFS.
- <VSO Project Name>: The project name in VSO
- <VSO Git Repo name>: The repository name in VSO. It’s usually the same name as the project, but with Git, you can have several code repositories in the same project, so we can specify it.
For example, providing a local TFS project called $"/tfs project name/src", we’ll save it locally to folder "C:\Git\Website", and then, push it to the repository "VSO src" in the project "VSO Project", like this:
C:\Git>git-migrate.bat $"/tfs project name/src" "Website" "VSO Project" "VSO src"
1.4 Handling user authentication
During the “push” process, you will be asked for your credentials on VSO, and it may happen that you email cannot login successfully. To fix it, you need to enable alternate credentials to your account in VSO. You can do it following these steps:
1. Login to http://<vso_account>.visualstudio.com
2. Click on “My profile” link
3. On the Credentials tab, choose “Enable alternate credentials”
4. Set secondary username (without “@”) and a password, and save changes
5. Use this new alternate credentials when you’re asked to login to VSO during the push process.