X
Closing this message and/or accessing our website tells us you are happy to receive all cookies on the ClearPeople website.
However, if you would like to, you can change your cookies settings at any time.
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 this Microsoft Article, 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 this online survival guide, and based on them, we got a nice batch script that allowed us to move smoothly all our projects to VSO.

 

Prerequisites

  1. Install Git-Tfs tool: https://github.com/git-tfs/git-tfs, and make sure it’s in the PATH
  2. 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

Batch file

Our batch file looks like this:


@ECHO OFF

set localRepo=http://<local_tfs_url>:8080/tfs/DefaultCollection
set remote=https://<vso_account>.visualstudio.com/DefaultCollection

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
GOTO continue

:usage
echo. 
echo Usage: git-migrate [TFS Repo] [Destination Folder] [Remote Project] [Remote Repo]
exit /b

:continue
set repo=%1
set folder=%2
set remoteProject=%3
set remoteRepo=%4

setlocal EnableDelayedExpansion
set remoteProject=!remoteProject:"=!
set remoteRepo=!remoteRepo:"=!
setlocal DisableDelayedExpansion

echo.
echo Migration TFS project "%repo%" to VS Online project "%remoteProject%" into repo "%remoteRepo%"

setlocal EnableDelayedExpansion
set remoteProject=!remoteProject: =%%20!
set remoteProject=!remoteProject:"=!
set remoteRepo=!remoteRepo: =%%20!
set remoteRepo=!remoteRepo:"=!
setlocal DisableDelayedExpansion

git tfs clone %localRepo% %repo% %folder%
cd %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>

 

Where:

  • <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.

Author bio

Sergi Gisbert
Sergio Gisbert
Technical Architect
I'm primarily focused on the delivery of successful projects with Kentico CMS. When I’m not at work, I’m running a personal project started 7 years ago called “Fatherhood," which takes up most of my non-working hours. I'm always keen to escape to snowy mountains and ski down them!

Comments


comments powered by Disqus

Related Articles

Sign up to our Newsletter

Every now and then, we'd like to send you information that delivers, develops and promotes our products and services that are relevant to you. Submitting your details tells us that you're OK with this and you also agree to our Privacy & Cookies policy. You can, of course, opt out of these communications at any time.