How to make TFS and Git to Play Nice: Taking TFS offline

In the last month I have started using git mainly mysysgit for all of my personal project and Team Foundation Server for work.  A few weeks ago I became aware of the git-tfs project which is an extension to allow you to use a local git repository with a TFS remote. 

One the things that has been a pain is that once you have the project cloned locally it still thinks that it is under source control and every time you open it you have to click through the dialogs.  There are a few workarounds online that show how to take the solution offline by turning off your wireless and unplugging your network card, then open the solution.  When you do this Visual Studio will prompt you to take the solution offline.  I am not a big fan of solutions that require unplugging the network to get a software package to do something it should natively. 

In this post I am going to show you how I was able to get my solution in the offline mode without messing around with the network settings.

So we want the solution to be offline, right? We’ll guess what? There is a Visual Studio Extension for that!  Install the GoOffLine Visual Studio Extension from the Visual Studio Extension Gallery – This extension adds a Go Offline menu option to the File->Source Control menu.



Now, we need a existing project cloned from TFS or to get a new one.  I am not going to go into the details of how to install and configure git and git-tfs there are several good resources available that cover that topic extensively.  That being said I will point you to the blog post that helped me figure out how to get git-tfs working: Git & TFS Working Together – Version 2 by Richard Banks. 

One hurdle I had to overcome was when I opened the cloned solution, which is not in the workspace, and clicked the Go Offline menu item nothing happened.  What I figured out was since the source code location wasn’t mapped in the workspace it didn’t take it offline.  Which makes sense because it asked during load if I wanted to remove the source control bindings or disable them temporarily.  I disabled them temporarily since I didn’t want to screw up any of the others working on the project that weren’t using git.

To get around this I open my Manage Workspaces and temporarily mapped the solution to the directory where I had the git repository for the solution.  Now when I opened the solution it was bound to TFS Source control and clicking the Go Offline menu option took the project offline.  I think closed the solution and removed the mapping from the workspace.

This leaves Visual Studio in offline mode, even when you want to open a solution that is mapped to TFS.  So to get around that go to File->Source Control->Go Online and it will bring Visual Studio back online and your TFS integration will light up.

When you open your project from the local git version (that is offline) you will see the following dialog.


Just click “No” and your solution will open and you can get started coding.

Using this technique will allow you to enjoy all the benefits of using a local version control with Team Foundation Server as the remote.  Today was the first day I have tried this and I hope others can help me figure out if there is a better way to approach this.  I am going to continue down this path and see if there are any gotchas I haven’t come across yet.  If you have a different solution about how to work with git on a project while everyone else is using Team Explorer with TFS I would love to hear it.

blog comments powered by Disqus


<<  July 2022  >>

View posts in large calendar

Month List