From TFVC to Git on VSTS
In the previous post we talked about strategies for migrating your TFVC source code hosted in an on-premise TFS server and into a VSTS account hosted by Microsoft. So before you consider moving on with TFVC you might want to consider having a look at Git.
Granted that you have an investment in TFVC and you know it well, but developing using Git has some advantages that I think you might like. If you would like to know more about whether TFVC or Git is right for your needs, you can take a look at this post: https://bit.ly/TFVCAndGit
In any case, I won’t try to sway your opinion either way, but if you are interested in migrating your TFVC to Git and retaining full source code history while doing it then please read on.
Migrating from TFVC to Git is pretty straight forward if you have a simple repository. For demonstration purposes we will conduct a simple migration from TFVC to Git, with just some history and no branches. The tool can conduct more extensive migrations involving branches, but doing so is beyond the scope of this post.
Before migrating, you should make sure a few things are in place. You will need to have downloaded and setup Git on your machine, along with the Git-TFS tool and lastly you should setup a new and empty Git repository in your VSTS account. The Git repository can be placed within the same project as your TFVC repository, this will make things simpler when migrating, however you are welcome to create a new project and repository in VSTS if you like.
Here is the list of tools you will need to download and setup. Please be aware that in order for the commands in this post to work, you have to setup the system environment path for Git and Git-Tfs:
- Git for Windows https://git-scm.com/downloads/guis
- Git-Tfs https://github.com/git-tfs/git-tfs/releases
- Visual Studio 2015 https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx
After setup, the next step is to run Git-Tfs to download the TFVC repository into a local Git repository. The conversion is done by Git-Tfs, which creates a new Git repository with the migrated code, you will then proceed to push that Git repository to the new remote Git repository you create in TFVC.
For instance, here is the new Git repository I created for my sample project in my VSTS project account. Notice that I have two repositories, of two different types, Git and TFVC and they are both under the same project:
Also, here is the sample project I created along with some history to go with it. At the end of the migration you will see how all of the history remains in Git:
One last thing to do before we run the migration is to make sure we have an empty folder where the migration tool can place the migrated project source code. If you don’t already have a folder to navigate to where you plan on placing the new GIT repository, you can just simply create a new Folder and go from there:
Now we are finally ready to migrate our source code along with our history. From the command prompt you currently have opened, go ahead and type this command and execute:
git tfs clone https://YOURVSTS.visualstudio.com/DefaultCollection “$/YourProjectRoot/YourSolutionDirectory”
Notice that in the command above I cloned the project from my VSTS URL and then I specified the path to the project containing my TFVC repository:
Now I have a Git repository under C:\MyContactsGitRepo in my local machine and all I need to do is push this local Git repository into the new empty one I created in VSTS. To make things even easier, when I navigate to my new empty Git repository in VSTS, I can find a set of commands that tell me exactly what commands to run in order to push my new local Git repository to VSTS:
Note that you will have to first ‘Generate Git credentials’ in order to push out to this repository. When you click on that button link you can either create a username and password combo or generate a token which you will use as your password when prompted by Git during the push of the repository to the remote location.
Once you got your credentials, navigate to the folder where the repository was created. we run the two commands under “Push an existing repository” subsequently:
And now when you navigate to your Git repository on VSTS, you will see the new migrated repository with all of the source code and history in it:
And there it is, a full TFVC to Git migration with history and all! I hope you have enjoyed this post and may the Git be with you.