8
votes

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.

3
There are two source control system provided by TFS. Git & TFVC. You cant push from one to the other OOB. Can you confirm which you are using server side?MrHinsh - Martin Hinshelwood
Note that TFS is a server that hosts things like Git repositories or TFVC repositories. Developing locally using Git and using TFVC to sync with others is not at all a mainstream use case for VS. As @MrHinsh points out: in VS you can use TFVC or you can use Git, but if you want a (lossy) translation between the two, VS will not do that for you.Edward Thomson

3 Answers

9
votes

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.

3
votes

If the server is configured for TFVC and you have a local Git repo then you cant just push from local to tfs. You have two options. You can:

1) You can create a new team project that is configured for Git and push as normal.

2) you can use TF-Git to push from your local git repo to the TFVC server: http://www.microsoft.com/en-gb/download/details.aspx?id=30474

0
votes

I switched to using mercurial for my local repository. This features no VS integration (needs external committing) but also no VS trouble.