In a previous article, I had explained Git and Git commands with Azure DevOps.
If the development team is already working on a centralized version control system and wants to move it to Git, learning only basic Git commands will not suffice! The development team also needs to know how the existing code can further be used by migrating it to Git. Taking this into consideration, in this tutorial, I will take an overview of the same.
Moving Code to Azure DevOps
I will also take up a case where code resides in Git but is on on-prem server, which needs to be migrated to Azure DevOps. The code can be available in earlier versions of on-premises Team Foundation Server (TFS) or in Azure DevOps Server 2019.
I will take the following cases:
CASE 1. Code is residing on a centralized version control (TFVC) in earlier version of Team Foundation Server (i.e. on-premises Team Foundation Server) – we do not need any history for the code to be migrated
CASE 2. Code is available on a centralized version control (TFVC), but in Azure DevOps – we do not need the complete history - just the last six months is enough
CASE 3. Code is available on a centralized version control (TFVC) in earlier version of Team Foundation Server (i.e. on-premises Team Foundation Server) – we need the complete history will all the branches to be migrated
CASE 4. Code is already available on a distributed version control system (Git) but is in on-premises Team Foundation Server or Azure DevOps Server 2019.
Case 1- Code resides on a centralized version control (TFVC) in earlier version of Team Foundation Server (No Code History Required)
The development team is using a centralized version control that is part of either Team Foundation Server version or with Azure DevOps Server 2019 as the source control. The team wants the code to be migrated to Azure DevOps – Git as a snapshot of the latest code. The team is not interested in any history of the code.
In this situation, we require the following steps:
1. Create an organization in Azure DevOps with the desired name (if it does not already exist)
2. Create a Team Project where the code is to be migrated with processes suitable for the team and client – Agile, CMMI or Scrum
3. Create a repository for the project in Azure DevOps if a different repo is required
Figure 1: Create a new repository in Azure DevOps
4. Get the latest code on the machine in a folder (this folder is mapped to the workspace for out TFS or Azure DevOps Server 2019). This can be done very easily by using Visual Studio 2019
5. Get git for windows and open the command prompt. You can download it from this link. It can easily be installed being an executable file. Browse to the folder which has been mapped to TFVC workspace in an earlier step
6. Create a local git repo by using following commands (open command prompt)
git init – will create a new git as empty
git add – will add all the changes in folder to stage
7. Now that we have created a local git repo we have to commit to the repo
git commit -m "<commit message>"
This step takes care of converting the code from centralized version control to distributed version control. But is still in the local repo.
8. As we need to finally send this code to remote repo in Azure DevOps, we need to set that
git remote add origin <url to your Azure DevOps repo>
9. Now we just have to push from local to remote
git push --set-upstream origin master
All our code from mapped workspace is now migrated to Azure DevOps which can be viewed by connecting to the repository.
Case 2: Code is available on a centralized version control (TFVC), but in Azure DevOps
The development team is using TFVC to store the code. The team is interested in the history of the code, but not the entire history. A recent history up to six months is sufficient. The development team feels that code history beyond six months can be kept in original source control and can be referred later if required.
In this case, you can directly use the wizard available in Azure DevOps. You can either create a new Team Project or use an existing one and select the option of Import Repository. This comes with the assumption that you are working in Azure DevOps but using centralized version control.
Figure 4: Import repo from TFVC to Git in Azure DevOps
We can give at the most 180 days (6 months) while importing code. Once the wizard starts, we do not have to do anything, all the code will be imported directly in the Git repository.
Figure 5: Import TFVC code to Git using wizard
You can observe that the commit comments are same as what you had provided at the time of check-in. But instead of changeset ids, you now have commit ids.
Case 3: Code resides on a centralized version control (TFVC) in earlier version of Team Foundation Server (Entire Code History Required)
The development team is working with a centralized version control and wants the complete history going beyond 180 days, along with all the branches from TFVC to be migrated to Azure DevOps git repo.
You must have observed by now that this cannot be taken care by the two Cases discussed earlier.
In this situation, we need to use the tool git-tfs which can be downloaded from this link.
We had used this tool for a consulting assignment for an MNC recently where they were interested in migrating all the history. Though the documentation says that the tool will suffice all the branches from TFVC, we cannot be 100% sure about it. Sometimes we have to migrate one branch at a time if there are sub folders in the branches (which is possible in TFVC).
1. The command to issue from command prompt is as follows:
Create a folder where you want all the code to be available, browse to that folder using command prompt
git-tfs clone <url to collection> "$/<project name>"
Observe the dot (.) at the end, which specifies current folder
2. In case you want to fetch all branches, you can provide the following command:
git-tfs clone <url to collection> "$/<project name>" . –branches:all
If the code base is huge, it will take a lot of time for the migration of the entire code. We need to ensure that the machine on which the command is running remains ON, without any failures and interruptions.
Figure 6: Clone the TFVC code to Git by using git-tfs tool
Case 4: Code is already available on Git but is on-premises Team Foundation Server (TFS) or Azure DevOps Server 2019
In this scenario, the development team is working with Git but hosted in Team Foundation Server (TFS) or Azure DevOps Server 2019.
The code needs to be migrated now to Azure DevOps.
The steps to update code in remote repo are the same as described in Case 2.
1. In this case, we already have a local repository which has remote origin to on-prem TFS or Azure DevOps Server 2019. Delete the existing remote origin by executing the command -
git remote remove origin
2. Now what remains is to provide the new remote origin – pointing to new Azure DevOps repo
git remote add origin <url to Azure DevOps repo>
3. Once the remote repo is created push the code to remote repo
git push --set-upstream origin master
Figure 7: Git push to repo
Conclusion
In this article, I have taken an overview of Code Migration from Centralized version control to Azure DevOps.
This article was technically reviewed by Subodh Sohoni.
This article has been editorially reviewed by Suprotim Agarwal.
C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.
We at DotNetCurry are very excited to announce The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).
Organized around concepts, this Book aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on the latest .NET Core 3.0, .NET Standard and C# 8.0 (final release) too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.
Click here to Explore the Table of Contents or Download Sample Chapters!
Was this article worth reading? Share it with fellow developers too. Thanks!
Gouri is a Trainer and Consultant on Azure DevOps and Azure Development. She has an experience of three decades in software training and consulting. She is a graduate from Pune University and PGDCA from Pune University. Gouri is a Microsoft Most Valuable Professional (MVP) - Developer Technologies (Azure DevOps), Microsoft Certified Trainer (MCT) and a Microsoft Certified Azure DevOps Engineer Expert. She has conducted over 150 corporate trainings on various Microsoft technologies. She is a speaker with Pune User Group and has conducted sessions on Azure DevOps, SQL Server Business Intelligence and Mobile Application Development. Gouri has written more than 75 articles on Azure DevOps, TFS, SQL Server Business Intelligence and SQL Azure which are published on
www.sqlservercurry.com and
www.dotnetcurry.com. You can connect with her on
LinkedIn.