Let's walk through creating a standard Build VM
You are here
Moving from TFVC to Git in AZDO
Moving from TFVC to GIT in Azure DevOps is easy!
I have some TFVC code repo in Azure DevOps that I would like to move to use Git. We're going to walk through the process of moving code from TFVC to Git on a single dev machine.
First, let's look at what we're going to be moving.
This is the project I'll be moving. It has years of history and also some garbage. But we'll be taking the development branch to moving it to a developer branch in Git.
Look at all that garbage! Now, before we can move the stuff we want to keep, we have to make a Git repo to store it. So, let's make a Git repo in our AZDO project. TFVC and Git can coexist in a AZDO project.
This will create a repo with a default branch, called master. Next, we'll want to create a branch for development. For this specific project, I am the only developer so we're making a branch JUST for me. With Git, there are different branching considerations and rules than with TFVC. We'll cover those later.
Notice that we can tie the branch creation to a work item. It's possible to create a branch for a work item and if you tie a work item to feature, bug, or anything else, you can setup development workspaces for each feature, bug or so on to keep commits targetted to a specific issue. Again, we'll cover this in greater detail later.
Next, open your dev VM and install Git Tools which can be found here: https://git-scm.com/download/win
Next, in Visual Studio, go to Tools > Extensions and Updates then install GitHub Extensions for Visual Studio.This step isn't required as such, just a personal preference. It's a great set of tools.
Next, connect to your Git Repo. In VS, open the Team Explorer and connect to your new repo. If you've already connected to your AZDO instance before, you should see it listed in your available repos. If not, connect like you normally would for TFVC.
Click Clone This Repository
Note the location, C:\Users\Administrator\Source\Repos\Sample Repo and click clone. Lastly, close all instances of VS.
Next, we'll want to do the following:
Move of copy the
.git directory to the destination path (PackagesLocalDirectory). Open Powershell as an Admin.
PS C:\Users\Administrator> Move-Item "C:\Users\Administrator\Source\Repos\Sample Repo\.git" "C:\AOSService\PackagesLocalDirectory\.git"
Next, we'll need to reset the repo
PS C:\Users\Administrator> cd C:\AOSService\PackagesLocalDirectory\ PS C:\AOSService\PackagesLocalDirectory> git reset --hard
Next, we'll need to add our TFVC package or packages if you have multiple. Here we only have one.
PS C:\AOSService\PackagesLocalDirectory> git add .\AAXWarehouseDimensionLink\
Next, we'll have to set some ACLs on our .git directory. If we don't do this, we'll see some errors in the event log.
PS C:\AOSService\PackagesLocalDirectory> Get-Acl -Path C:\AOSService\PackagesLocalDirectory | Set-Acl -Path C:\AOSService\PackagesLocalDirectory\.git
Now we can close PowerShell and open VS again. In the Team Explorer tab, go to Manage Connections and open your PackageLocalDirectory from your local Git Repos.
Double click then go to changes. You should see the package(s) that were added above.
Next, go to Settings > Repository Settings then click add next to "There was no .gitignore file found" or edit if you created a template when created your Git repo.
At the end of your .gitignore file, add a section like the following. Modify it for your specific instance.
# Ignore everything
# But keep custom packages and models
# keep Projects
Next, we'll need to change were we keep our Project files. In Visual Studio, Go to Tools > Options then find Project and Solutions on the left:
To keep VSProjects in version control, we need to relocate them to a path within the git repository. We'll need to change the project locations from something like C:\Users\administrator\Documents\Visual Studio 2015\Projects to something like C:\AOSService\PackagesLocalDirectory\VSProjects.
First, execute the following in PowerShell. We'll need to copy our projects from the old location do the new, like so in PowerShell:
PS C:\AOSService\PackagesLocalDirectory> Move-Item "C:\Users\Administrator\Documents\Visual Studio 2015\Projects" "C:\AOSService\PackagesLocalDirectory\VSProjects\"
And also add our projects to Git:
PS C:\AOSService\PackagesLocalDirectory> git add .\VSProjects\
Next, update the settings above in VS to match where the projects now currently reside.
After that, all we have to do is stage, commit, and sync all of our changes.
Note that a .gitattributes file is optional.
Next, we have to do some cleanup on this machine. First, we need to switch back over to TFVC. Go to Manage Connections then open the TFVC Workspace. We'll need to unmap all directories. To do this, open Source Control Exploror, find your branch, find the map folders, Right Click, go to advanced > Remove mapping.
We can close Source Control Explorer once everything is unmapped. During unmapping of folders, TFVC will have deleted some or all of our code from disk. We want to reverse that pending change. Let's flip over to Git (Manage Connections > Local Git Repos > PackagesLocalDirectory). Go to Changes, right click on the first item then select "Undo Changes".
And we're done. We'll need to remove access to the TFVC repos to prevent anyone from committing changes but leave read access for historical purposes - just to look up who made what changes when. Now that we're in Git, we have to talk about branching and merging strategies but that's for next time. We'll also need to get our build pipelines setup again, too!