16
votes

I'm in a situation where I need to run both TFS and Git side by side. I will need to switch between the two. Git is installed and configure to run locally. TFS is run on a company server. How do I switch between the two environments in Visual Studio 2013?

I am open to switching to VS 2015 if git integration has improved.

VS first detected Git and then switched over to that source control in "Team Explorer". I stumbled onto a way to switch to TFS (that I do not recall) and now I don't know how to switch back to Git.

If you care, I need to run Git side by side with TFS because I'm not allowed to create branches in TFS and there's no way I'm going to play around with commits in the Main trunk or manage N number of shelvesets. I'm going to use feature branches

4

4 Answers

11
votes

If you want to use a TFS workspace and also use GIT then you can switch between them using Team Explorer. Hit the "plug" looking item at the top of the screen and you can switch between them there. The screen shot is from VS 2015 but the UI hasn't changed much from 2013

Team Explorer

If you want to use git exclusively on your local machine and but push to TFS on the server then take a look at "git-TF"

You can clone your "Trunk" from TFS to a local git repo, work exclusively in git and use feature branches etc. When your code is ready to send back to Trunk then you can rebase and push i.e.

git-tf clone http://myserver:8080/tfs/mycollection $/TeamProjectA/Trunk

Make changes to the file in the Git repo

git commit -a -m "commit one" (commit changes locally)

Make more changes

git commit -a -m "commit two"

git-tf pull --rebase

git-tf checkin

6
votes

Not the most elegant solution, but it's straightforward and doesn't require 3rd party tools (assuming you already have a git shell)... I simply rename the .git folder to something else before starting studio and it'll use TFS. As soon as the solution is open, you can then rename the git folder back to ".git" and do anything git-related via a bash shell.

mv .git git
(open the solution in VS)
mv git .git

At this point, you can check in/out using TFS through IDE, and push/pull using git via the shell.

NOTE: One thing you'll have to watch out for is if new files are added from the git side (ie, via a git pull) Studio will list them under "Excluded Changes > Detected: ### adds" so you'll have to "Promote" them.

2
votes

I had big problems trying to swap from GIT to TFS.

Even attempting to open my project would just fail... none of the Solutions or its Projects would load.

In the end, the only thing that worked was to manually move the (hidden) .git folder elsewhere. Only then could I open the Project via TFS, and see the friendly TFS context menu items ("Check in", rather than "Commit", etc)

2
votes

I've been having this problem as at work we use TFS and I prefer to use git for local tracking of files. (Hopefully company is moving to git soon with some pushes from me...)

What I've found works is to make these aliases. alias degit="mv .git git" alias regit="mv git .git"

'degit' your repo as it were, before you launch VS2015 with TFS set as your source control, once it's all loaded up, 'regit' your repo. Seems to work well with me. Again though, I'm not currently using git for pushing to a remote. Still doing that using TFS.