Migrating from TFVC to Git with and without History

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 would focus on Migrating from TFVC to GIT.  

Learn more about our Azure DevOps offerings!

Learn More


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 to switch or merge branches as there is no need to communicate to a remote server. 
  • Storage: The way of storing changes also varies in both these Version Control Systems. Team Foundation Version Control System stores the changes per file, also called changeset. Contrary to this, the files in a git commit are saved as a snapshot that makes reverting a whole commit or multiple commits easy.  

Reasons for Migrating: 

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

How to migrate from TFVC to Git 

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 like GitHub, bitbucket, Azure DevOps, or alike.  
  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, Click add TFS server, provide the URL to the server and click add.  

Connect to a Project | TFVC to Git

3. When the server will be added, it will give us the option to map a local directory to where we want our code to be cloned. 

map a local directory | migrate from TFVC to Git

4. Install git for windows and initialize a git repo using the following command: 

git init 

5. Copy all the code that we had cloned in the previous step to the empty local repo (directory) we have just Created.  

6. Stage all the changes to commit by using the command: 

git add .  

7. Set the remote repo by the command: 

git remotes add origin <url to your repo> 

8. Now commit the changes with a meaningful commit message. 

git commit -m “<commit message>” 

9.  Now the only step left is pushing the code to the remote git repo. That can be done by: 

git push origin master 

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 select the repo options. Select Import Repository under the Repos dropdown.  

Import Repository | migrate from TFVC to Git

2. Import Repo pop-up will be popped 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).  

Migrate History

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

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

For migrating 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’)) 

2. Install git-tfs by executing the command using PowerShell in the Administrative mode 

choco install gittfs 

3. Once the gittfs are installed, we need to add its folder in the path. The following command can be used for that. 

set PATH=%PATH%;%cd%GitTfsbinDebug 

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

5. 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>/”.   

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

Final Thoughts:  

When we compare git and TFVC, we realize that there are numerous causes of using git, e.g., how it deals with the changes, its branching and merging strategies, it is Distributed Version Control System. Most importantly, Microsoft itself 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 Team Foundation Version Control System, and you want to migrate to git.