Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using both local Git and (remote) TFS with Visual Studio 2013

I started work on some code locally and used Git (Git Gui and command-line) to manage it. I've now been asked to put the project into TFS "at corporate". I can access TFS remotely using a VPN connection.

The code is, to VS, a single solution with multiple projects. I successfully added the solution to TFS using VS, and it seemed to find all the projects and add their .csproj files and all the code to TFS source control.

Later, when not connected to TFS (VPN off), I made a simple change and committed it to my local Git repository. I have had nothing but frustration attempting to (connect to the VPN and) try to commit the change to TFS.

  • I start Visual Studio.
  • There is a "Team Explorer - Home" tab that has "Home | Offline" showing.
  • I check Tools / Options / Source Control and TFS is the current version control provider.

So far so good.

  • I click the "plug" icon on the Team Explorer toolbar; it remembers the connection and now shows "Connect | Offline";
  • Below is a line with a link "Select Team Projects..." and two sections with down-pointing triangles next to each.
    • One has the TFS server name (followed by (1)); under that is the name of the (only) "team project" where this is stored in TFS.
    • The other section has "Local Git Repositories (1)" and shows the name of the solution with the path to the solution directory next to it.
  • The tab title is "Team Explorer - Connect".
  • I double-click the name of the team project and the tab title changes to "Team Explorer - Home" and the screen shows "Home | {teamProjName}" and two sections.
    • One has "Project" with "Web Portal" and the usual "Pending Changes", "Source Control Explorer", etc icon sections below that;
    • And there's another section "Solutions" that has a line "Workspace: {workspaceName} | New... | "Open...";
    • Below that is the single solution file.
  • I double-click the solution name, and now the screen shows "Home | solutionName (Local)";
    • The Solutions section now has "Branch: master" (evidence of Git) and
    • Tools / Options / Source Control says it's changed to the Microsoft Git Provider.
  • If I change it back to TFS, it says "Home | Offline" and I have to click the "plug" icon again --

And I'm right back where I started, except that it says "Connect | {solutionName} (Local)"!

Opening the solution first doesn't help; when I connect to TFS the solution gets closed. Closing and opening VS just has it start in "VS knows about TFS, but you're offline" mode and opening the solution with TFS active makes it switch to the Git provider in (Local) mode.

I am very close to doing the registry hacks to disable the Microsoft Git Provider -- I've done my Git work using Git Gui and the commandline; VS has not been involved.

Am I crazy? I would have thought that "develop locally using Git, connect to TFS to sync with others" was a mainstream use case for VS.

Any assistance would be appreciated. Thanks.

like image 504
J.Merrill Avatar asked Jan 26 '15 16:01

J.Merrill


1 Answers

Visual Studio only sees git repositories if the .git folder is used as the store for the git repository. So, we can fake-out VS by using a different folder for the git store.

  • Rename the current .git folder to _git (.git dir may be hidden)
  • Create a text file in that same folder called .git containing just the line gitdir: _git (make the file via command line: echo gitdir: _git>.git)
  • Add _git to your .gitignore file

Now when you launch VS it will not see that git repository and will use TFS instead.

like image 154
blalond Avatar answered Sep 30 '22 10:09

blalond