8

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.

ruffin
  • 16,507
  • 9
  • 88
  • 138
J.Merrill
  • 1,233
  • 14
  • 27
  • 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 Jan 26 '15 at 20:00
  • 2
    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 Jan 26 '15 at 20:13
  • Update: VS code does not support TFVC version control – Isaacnfairplay Jul 12 '23 at 17:27

3 Answers3

9

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.

blalond
  • 875
  • 10
  • 17
  • I have used this solution for many years, but now that I have upgraded to VS2019 it seems like Visual Studio reads the .git file and uses the _git folder anyway. – Anlo May 07 '20 at 13:28
  • I think something changed with VS2019 recently. This was still working for me a couple weeks ago. My team just fully changed over to Git last week! To test this I opened in VS2019 my old .sln that is still under TFS and it now bumps right over to the Git using the _git. – blalond May 08 '20 at 15:09
  • 2
    I tried lots of ways to make make VS2019 use TFS even though there is a .git folder in a parent folder and finally found a reasonable solution: https://stackoverflow.com/a/61658693/306074 – Anlo May 09 '20 at 09:52
  • @Anlo Since 2019 breaks this answer, it's probably worth bringing yours over to this question as well before it gets marked a dupe. ;^) I started here and appreciate the link to the other. – ruffin Sep 18 '20 at 16:42
  • @Anlo Looks like it was [auto-flagged for being an exact duplicate](https://meta.stackoverflow.com/questions/401400/a-high-value-answer-was-mod-deleted-without-explanation-afaict-whats-the-right/401403#401403) of your answer to that question. Probably worth an edit and repost here. blalond -- sorry to comment on your answer. Will clean these back off soon. – ruffin Sep 21 '20 at 21:24
3

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

  • 2
    I am not trying to "push from local Git to TFS". I am just trying to use server-side TFS version control without VS continually dropping into offline mode simply because I have a local Git repository. I am perfectly willing to do commits to my local Git -- while working on things -- separately from committing "finished work" to TFS. I just don't understand why the presence of a local Git repository makes VS continually ignore the connection to TFS. – J.Merrill Jan 27 '15 at 14:24
0

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

MKesper
  • 456
  • 5
  • 16