Moving Repositories from TFS
local graph
Chapter 8 — Moving Repositories from TFS
Section titled “Chapter 8 — Moving Repositories from TFS”Team Foundation Server (TFS) is the collaboration platform and foundation of Microsoft’s Application Life Cycle Management (ALM) solution, which comes with code version management (including package management (NuGet, Maven, and so on)), work item management, extensive reporting and dashboard capabilities, automated build and release management, and test management. Through extensive integration with development tools such as Visual Studio, TFS is used to communicate and collaborate with the process of designing, building (continuous integration), testing, and deploying (continuous delivery) the software, which should ultimately be used to increase productivity and team output, improve quality, and gain more insight into the application life cycle.
In this chapter, we will compare TFS to Git, and then we will migrate a TFS repository to Git that is in the old TFVC (Team Foundation Version Control) format. Note that, nowadays, Microsoft has standardized on Git for version management, so TFVC is not widely used anymore.
In this chapter, we will cover the following topics:
- TFS versus Git
- The git-tfs tool
To follow along with the instructions in this chapter, please download this book’s GitHub repository, along with the examples, from https://github.com/PacktPublishing/Mastering-GitLab-12/tree/master/Chapter08.
The other requirements for this chapter are as follows:
- Git: http://git-scm.org
- Azure DevOps account: https://azure.microsoft.com/nl-nl/services/devops/
- Git-tfs: https://github.com/git-tfs/git-tfs
- GitLab account: (https://gitlab.com or on premise)
Microsoft created TFS as a product to help teams create software.
It has the following features:
- Source code management
- Requirements management
- Lab management
- Reporting
- Project management (for Agile software and waterfall development)
- Automated builds
- Testing
- Release management capabilities
The solution was created to help across the entire life cycle of the product (ALM). It can cooperate with several Integrated Development Environments (IDEs), but works best with Microsoft’s own Visual Studio, which nowadays is multiplatform.
It has been around for some time, but currently the focus is on getting customers to use the Cloud version of TFS: Azure DevOps. You get all the features of TFS on premise, but it is much more scalable.
For source code management, two different kinds of repositories are supported. Originally, the default was Team Foundation Version Control (TFVC), which resembles SVN and is very much a centralized Version Control System (VCS). The other choice is Git. Over the past few years, Git has been adopted as the default VCS within Microsoft. You probably won’t find a team that doesn’t use Git within Microsoft (well, maybe the team that’s responsible for TFS).
If you want to migrate your TFS Git repository to GitLab, it’s very easy. For instance, you can move a repository to a new one in an on-premise GitLab:
cd existing_repogit remote rename origin old-origingit remote add origin https://gitlab.example.com/me/newprojectingitlab.gitgit push -u origin --allgit push -u origin --tagsMigrating a TFVC project takes a bit more effort, which I will explain later. First, let me explain the differences between TFVC and Git. We will start with the most important one: whether it is centralized or decentralized.
The basic design of TFVC is that of a centralized repository on a server with authorized clients connecting to it to exchange information. Git’s distributed nature is the complete opposite, with no central authority by default and the possibility to freely push and pull changes with others. Of course, you can create a central server that harbors a copy of the Git repository that everyone agrees is the newest version. This difference can be seen in the following diagram. The Git repository can exist in a local TFS or the Azure instance, while the TFVC one can only exist in one central place:

The best tool that you can use to work with TFVC is without a doubt Visual Studio. Let’s discuss some points regarding the way it handles changes in your files.
Compared to branches in Git, which are repository scoped, TFVC branches are path scoped and not as lightweight. Generally speaking, team members create additional workspaces for each branch they are working on. Changes are branch-independent, so to avoid chaos at integration time, you need to forward-integrate as many times as possible. The standard merge with TFVC uses a two-way merge (baseless).
Set your bar for creating branches high and only branch when you have a need for code or release isolation. It’s more resource-intensive to use branches in TFVC. As the number of your feature branches increases, so do your storage requirements and branch hierarchy visualization fuzziness. In the following screenshot, you can see the situation as a developer; you can’t merge because of conflicts:

In Git, a branch is only a pointer to a commit. The default diff in Git uses three-way merging, which also helps developers merge back.
Because of the centralized nature of TFVC, some pieces of information are not available when you are not connected. File history is not replicated to the client’s development machine and can only be viewed when you are online with the server. This information is viewable via Visual Studio and the web portal. Via the context menu of an item, you can annotate files to see who changed a line, and when they changed it. The following screenshot shows what sort of information is given in the web portal:

With Git, file history is replicated on the client’s development machine. You can also view it when there is no connection to the TFS server. You can view history in Visual Studio and on the web portal, as well as on the specific Git server you are using, such as GitLab. By using Git’s command option, you can find out who changed which lines in a file, and why. It can be a useful tool for identifying changes in your code as annotation is in TFVC. See the following git blame command:
$ git blame BSDLicence e2cc9eb2 (peter 2010-01-08 20:35:51 +0000 1) The files e2cc9eb2 (peter 2010-01-08 20:35:51 +0000 2) e2cc9eb2 (peter 2010-01-08 20:35:51 +0000 3) !PDF.Res e2cc9eb2 (peter 2010-01-08 20:35:51 +0000 4) !PDF.Sprites e2cc9eb2 (peter 2010-01-08 20:35:51 +0000 5) !PDF.Sprites22 e2cc9eb2 (peter 2010-01-08 20:35:51 +0000 6) !PDF.Messages e2cc9eb2 (peter 2010-01-08 20:35:51 +0000 7) !PDF.Documents.Help/html e2cc9eb2 (peter 2010-01-08 20:35:51 +0000 8) !PDF.Documents.Help/txtWe can see that peter changed this file.
For some use cases, it is of the utmost importance to have good traceability. Think of companies such as banks and insurance companies who have to adhere to strict policies because of legislation. Since TFVC is a centralized repository type, its traceability is quite good out of the box. All change operations are recorded on the server and performed only by authorized individuals. There are direct links between issues, bugs, boards, and backlog items.
With Git, it is possible to setup the same system, but you need to make sure that your centralized repository enforces some extra checks and handles linking between entities (issue tracking in GitLab, for instance). By default, anyone can change the history of a Git repository, so out of the box, the traceability in Git is not very good.
Another big difference between Git and TFVC is when it comes to handling changes. This is connected to the fact that TFVC uses a central repository and Git is, by its nature, distributed. TFVC, with its central server, keeps all the files in a project under a single root path. Within this context, it is possible to apply permissions at a file level or lock files on the central server. By default, this is not possible with Git or with the basic GitLab configuration since there is no central place where you can enforce these authorizations. You can lock files somewhere, but a developer can happily continue developing locally and change code.
On the other hand, with Git, you can have multiple repositories in a GitLab project and have protection on a branch level or repository level. You have the option to define multiple remotes to which you can push code. This means that you can store code in GitLab and also on Windows Azure. The following screenshot shows the menu that you can use to lock a file in TFVC:

With TFVC, the files are all under one path and under control while in Git, there can be many branches and files spread over different remote servers. It’s hard, if not impossible, to enforce centralized control.
There are several ways to migrate data from TFVC to Git. The simplest way is to do the migration in TFS itself. You can use their own import/export tools from the https://docs.microsoft.com/en-us/azure/devops/repos/git/import-from-tfvc?view=azure-devops&tabs=new-nav&viewFallbackFrom=vsts website.
There is also another tool that can be used for migration. It is possible to have a bi-directional gateway between TFS and Git, just like there is with git-svn. It can put TFS commits into a Git repository, and allows you to push back changes to TFS.
The existence of these tools is caused by the fact that Microsoft internally switched to Git years ago and they have contributed a lot of source code to the codebase of Git. That is why it is standard (especially with Azure) to create new repositories using the Git format nowadays.
In this section, we will demonstrate how to migrate a TFVC project located on Azure DevOps. First, we will locate our project on Azure DevOps. You can do this by navigating to your organization at https://dev.azure.com. Setting up an organization is outside the scope of this book, but it is quite easy and free if you are a small company or an open source project. You can read more about this on the Azure page, here: https://azure.microsoft.com/nl-nl/services/devops/.
The project page for the git-tfs migration tool can be found on GitHub (https://github.com/git-tfs/git-tfs). Before you install git-tfs, there are a few prerequisites you need to take into account:
- You need a Windows machine to install it with.
- It has to have Git for Windows.
The git-tfs binaries can be downloaded from https://github.com/git-tfs/git-tfs/releases. Alternatively, you can do a managed install with chocolatey (https://chocolatey.org/). Installing with such a package manager takes care of the necessary details for you. Of course, you could build the package yourself because the source is also available. For these examples, we will use a basic Windows machine I already have set up. Let’s get started:
- It’s easy to install Git using chocolatey:

- The next step is to install git-tfs using the gittfs package:

- In order to perform the migration, we need to create a new project in our GitLab instance so that we have a destination for our Azure DevOps project:

- Now, we will use the git-tfs tool to clone the test project we created in Azure DevOps. It will bring up an authentication window:

- It will automatically search through change sets and convert them into Git:

- To copy this local Git repository to our GitLab project, we need to create a remote entry:
C:\git\MovingToGitlab>git remote add origin https://gitlab.joustie.nl:8443/root/movingtogitlab.git- Then, we will use push -u to push it to GitLab. Git for Windows will present you with a login screen, which you can authenticate against gitlab.joustie.nl:

- When the migrations are finished, you can log in to your GitLab project. Here, you will find the pushed code:

- You can view the commit history in Git with git log:

- If you compare it with the history in TFVC, you will find it to be the same:

By using the git-tfs tool, it is relatively easy to migrate your existing TFVC to Git.
This chapter explained what TFS is and where its place is in the Microsoft product gamma. First, we compared TFVC and Git in terms of their architecture, as well as the way they handle branching and merging. We also took a look at how they treat history and the traceability of changes.
From there, we learned that there are different ways to migrate from TFS to Git. For one, you can export from the server itself. There’s also a tool that you can use to create a mirror between a TFS and a Git repository that’s called git-tfs.The most logical reason for this tool to exist is because, nowadays, Git relies heavily on Git repositories and needs to convert TFVC projects into Git format internally.
This chapter ends the part of this book about migrating data from other systems to GitLab. In the next part, we will extensively discuss the ways of connecting to GitLab.
- What is TFS used for in Microsoft’s ALM suite?
- What is the biggest difference between TFVC and Git?
- TFS is part of what product in Azure?
- How do you migrate a TFS Git repository to GitLab?
- How are branches scoped in TFVC?
- Where is history kept with TFVC?
- What tool resembles git-tfs?
- What tool on Windows makes it easy to install Git?