Migrate TFVC to Git


Git is now the default version control provider for new Team Projects and it should be your first choice for version control unless you have a requirement for centralized version control system (TFVC).

If you want to migrate from TFVC to Git you can use the git-tfs utility.  You can use two methods to install git-tfs, one of which is to use Chocolatey.  I’ll open a command prompt to run choco install gittfs

snag-3582

choco install gittfs

You can verify it’s installed by typing the command git tfs help

snag-3583

git tfs help

First I’ll change directories into where I keep all of my other Git repos and then issue a list remote branches command to list all of the TFS branches that could be cloned

snag-3585

git tfs list-remote-branches

For this post I’m going to clone AIDEMO by executing the following command

git tfs clone https://like10.visualstudio.com/ $/AIDEMO

snag-3586

git tfs clone

Now that I have cloned it locally I should create a new Git repository in VSTS to push all the changes to

snag-3587

Create a new (empty) repository

 

snag-3589

choco install gittfs

Now we’ll add a remote to my local git repository and push all of the changes

  1. I make sure I’m in the AIDEMO folder
  2. git remote add origin https://like10.visualstudio.com/DefaultCollection/_git/AIDEMO
    NOTE:  You can get the Clone URL as shown in the screen capture above
  3. git push –all origin

 

snag-3588

git remote add origin

 

Ths is great except now we have the entire repository cloned but because we cloned from the root of the project we cannot manage branches.  Take a look at the screenshot below and you’ll immediately see what I mean:

snag-3592

Why are both of my branches is master?

 

 

Let’s try again but this time we’ll specify $/AIDEMO/main so we can manage our branches.  Open a prompt and execute the following command, this time specifying the root branch:

git tfs clone https://like10.visualstudio.com/ $/AIDEMO/main try4 –branches=all

snag-3591

git tfs clone –branches=all

Now I can change directories into the folder where I did the clone and list all of the branches in my local repository by executing the git branch command I can see both master and dev branches

snag-3593

git branch or git branch -v

Now I’ll create an empty Git repository in VSTS called AIDEMO5 and configure that as my remote by executing the following commands:

  • git remote add origin https://like10.visualstudio.com/DefaultCollection/AIDEMO/_git/AIDEMO5
  • git push –all origin

Here is the result of running those commands

snag-3594

git push –all origin

Now if we take a look at the Code Hub in VSTS we should see both of our branches

snag-3595

Code Hub with both branches

Here is a link to some documentation which goes into more details and some of the different options:

https://github.com/git-tfs/git-tfs/blob/master/doc/usecases/migrate_tfs_to_git.md

Good luck!

 

 

About wesmacdonald

Wes MacDonald is a Visual Studio ALM MVP, PSD, MCT and a Principal Consultant for LIKE 10 INC., a SharePoint Server, Visual Studio and Team Foundation Server Consulting Firm providing premium support and guidance services.

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: