Migrating from TFVC to Git with and without History

Introduction

In 2019, the Team Foundation Server (TFS) was rebranded as Azure DevOps Server. TFS came with many Microsoft-based tools, including Team Foundation Version Control (TFVC). TFVC is a centralized version control system developed by Microsoft. In comparison, GIT is another Version Control System. Here, we will focus on migrating from TFVC to GIT.

Learn more about our Azure DevOps offerings!

TFVC and Git Differences

  • Distributed VS Centralized: Team Foundation Version Control system is a Centralized Version Control System (CVCS), which means it is based on a Client-Server architecture. In contrast, GIT is a Distributed Version Control System (DVCS) where each person sharing a repo would have a separate copy downloaded to his system, making it more flexible to work.  DVCS is more convenient for switching or merging branches as there is no need to communicate with a remote server. 
  • Storage: The way of storing changes varies in both these Version Control Systems. Team Foundation Version Control System stores the changes per file, also called the changeset. Contrary to this, the files in a git commit are saved as a snapshot, making reverting a whole commit or multiple commits easy.

Reasons for Migrating from TFVC to Git

  • Licensing: We can use GIT without cost and license, whereas Team Foundation Version Control is proprietary. 
  • Easy to Learn: We can kickstart git easily because of the huge community and online tutorials.

Migrate to Azure DevOps with ease!

 Leverage the power of Azure DevOps to streamline your software development lifecycle, from planning and coding to deployment and monitoring.

Request a Consultation

Migrating from TFVC to Git - The Process

Case 1: Code is on TFVC hosted on a Team Foundation Server – No History

Suppose we have a case where the team uses Team Foundation Version Control as its Version Control System, and we want to migrate the code from TFVC to Git without considering the history. This is a simpler case. For this, we must follow the mentioned steps: 

  1. Create a remote git repository to which we want to push our code. We can use any code hosting platform for version control, such as GitHub, Bitbucket, Azure DevOps, or similar.  
  2. Get the latest code from Team Foundation Version Control locally. You can use Visual Studio for getting the code. From the team explorer in the Visual Studio, click on Manage Connections, Add TFS server, provide the URL to the server, and click Add.  
this image shows Connect to a Project | TFVC to Git
  1. When the server is added, we can map a local directory to where our code will be cloned.
this image shows map a local directory | migrate from TFVC to Git
  1. Install git for Windows and initialize a git repo using the following command:
    git init
  2. Copy all the code we cloned in the previous step to the empty local repo (directory) we Created.
  3. Stage all the changes to commit by using the command:
    git add.
  4. Set the remote repo by the command:
    git remotes add origin <url to your repo>
  5. Now, commit the changes with a meaningful commit message.
    git commit -m “<commit message>”
  6. The only step left is pushing the code to the remote git repo. That can be done by:
    git push origin master 

Read more: Simplify your Azure Infrastructure with Azure Blueprints

Case 2. Code is on TFVC hosted on Azure DevOps – History up to 180 days (about 6 months):

In case we have a team that is using Azure DevOps TFVC for code, and we want to migrate the code to the Azure DevOps git along with up to 6 months of history.  For this, we can use the Azure DevOps wizard for migration. We can use the Import Repository option available in the Repo Section of the project to which the code needs to be pushed.

For this, we need to follow the mentioned steps:

  1. Navigate to the project from the left pane and select the repo options. Select Import Repository under the Repos dropdown.  
this image shows Import Repository | migrate from TFVC to Git
  1. The Import Repo pop-up will pop out. From the Repository type, select TFVC. Give it the path of the Azure Hosted TFVC that needs to be migrated to git. If we want to migrate the code with History, check the “Migrate History” option. It will ask for the number of days of history we require. According to Microsoft documents, we can only take the history of 180 days (about 6 months).
this image shows Migrate History

Simplify your code migration process with Azure DevOps Services!

Focus on what matters most - your code - and let us handle the migration complexity.

Request a Consultation

Case 3. Code is on TFVC hosted on a Team Foundation Server – With a Complete History:

Here comes the most complex case, i.e., a team sharing the code using the Team Foundation Version Control System hosted on a Team Foundation Server. We need to migrate the code from TFVC to Git with complete history.

To migrate the code from TFVC to git with complete history, we need a tool named git-tfs. It is a two-way bridge that allows communication between git and TFVC. You can install git-tfs either using the binaries or using Chocolatey. These are the steps to follow for this case: 

  1. Install Chocolatey by executing the following command using PowerShell in the Administrative mode

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString(‘https://chocolatey.org/install.ps1’)) 

  1. Install git-tfs by executing the command using PowerShell in the Administrative mode:
    choco install gittfs
  2. Once the gittfs are installed, we must add its folder to the path. The following command can be used for that.
    set PATH=%PATH%;%cd%GitTfsbinDebug
  3. If we want to migrate all the branches from TFVC to git with History, we will run the following command. Only the branches would be cloned, and if there were some folders, those would need to be converted to a branch first.
    git-tfs clone <url to collection> “$/<project name>”. -branches:all
  4. If we want to migrate a single branch from TFVC to git with complete history, then:
    git tfs clone <url to collection> “<path to the branch>/”.
  5. When all the data needed is cloned, we can copy that to a local empty git repo and then push it to the origin described in case2. 

Read more: Pioneering the Digital Frontier: Azure DevOps vs Jira – An Executive’s Dilemma

Conclusion

When we compare git and TFVC, we realize there are numerous causes of using git, e.g., how it deals with the changes, its branching and merging strategies, and it is a Distributed Version Control System.

Most importantly, Microsoft recommends using git instead of TFVC unless there is a specific reason for using a CVCS. Hopefully, this blog will help you If you have any project that is still based on the Team Foundation Version Control System and want to migrate to git.

Explore Recent Blog Posts

Infographics show the 2021 MSUS Partner Award winner

Related Posts

Receive Updates on Youtube