[D365] Migrate from TFVC to GIT

Today I finally had time to move one of our projects in VSTS from TFVC to GIT source control!

Git has a lot of benefits like working offline (commit, revert, reset etc.), branching (even from WorkItems directly!) and others that I don't want to discuss here.

I want to share a quick step by step guide how to move from TFVC to GIT and what to take care of during the process.

You can move from TFVC to GIT in under 5 minutes!

This was the statement I got from Abel Wang (@AbelSquidHead) and Donovan Brown (@DonovanBrown) at the OOP 2018 in munich so I took the challenge.

What will be different?

Projects
Either the Projects folder will not be tracked by version control anymore or it needs to be relocated within the repo. We came to this conclusion as a GIT repository needs to be mapped completely to a local directory and we did not find a way to map parts of it like we used to with TFVC. For a solution, see the last point.

Working offline
Developers will no longer need to be online to use the benefits of version control. They can commit, revert to it and reset their codebase totally local from now on!

Branching
Branches can now be created from work items directly with a right click action!

Reviews
There is more comfort in reviewing changes with git support than TFVC had.

Pull Requests
Another problem with changes being directly merged into a branch after a review will be solved due to gits ability to open pull requests which can be set up to need another confirmation and has an awesome cherry picking feature!

Lets get started

Create a git repository in VSTS

Navigate to the Code Section in VSTS and create a new repository:
Choose a name and proceed without initializing README and gitigonore files:

Clone the new repo temporary

Since git can't clone a repository to an existing non-empty location, we use a little trick to get it working.
At first, we will clone the repo to any new path and then move the .git directory to our existing AOSService\PackageLocalDirectory path.

Set access rights to the .git folder

If you don't set them, you will likely see the following error in the eventlog preventing the AOSService to start:

Relocate Projects

To keep VSProjects in version control, we need to relocate them to a path within the git repository.
Original Path: C:\Users\USERNAME\Documents\Visual Studio 2015\Projects
New path: C:\AOSService\PackagesLocalDirectory\VSProjects
Change the settings in Visual Studio under Tools>Options:
And add the following line to your .gitignore file to whitelist the folder:

!/VSProjects

References

Don't forget to check and tweak your build definitions to point to the git repo!

Final notes

It took me exactly 4 minutes and 38 seconds to migrate from TFVC to git!
I need to mention that the codebase in this example was not very large.