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!
Â
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:Â
- 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. Â
- 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. Â
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.Â
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:Â
- Navigate to the project from the left pane select the repo options. Select Import Repository under the Repos dropdown. Â
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). Â
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.Â