Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect an existing local git repository to its existing remote repository in Visual Studio 2013?

I've just upgraded to Visual Studio 2013 and want to use the built-in git features.

I have a local git repository - with various branches and history - that I've been cheerfully working with a remote TFS git repository along with other colleagues.

In VS2013, I can see that local repository and switch branches, commit, push, etc. but when I connect to the team project, it has no branches and no connection to the local repository.

I can clone the remote to a new local folder, but not sure how to link the existing folder to it.

It's all working with the GitHub app for Windows, but the VS2013 tools don't seem to like it.

Any ideas?

like image 267
Fijjit Avatar asked Jul 01 '14 11:07

Fijjit


People also ask

How do I link my GitHub to Visual Studio repository?

In Visual Studio, select Team Explorer from the View menu. In the Team Explorer pane, click the Manage Connections toolbar icon. Click the Connect link in the GitHub section. If none of these options are visible, click Manage Connections and then Connect to GitHub.


2 Answers

I know this is an old question, but it came up in my Google search...

If your source code is not already in TFS, you'll need to clone your empty TFS project (use Visual Studio), then pull in the code from your other repo and push it to TFS (Daniel's answer).

If your source code is already in TFS, but Visual Studio isn't associating your existing local git repo with the TFS project...

In Visual Studio, connect to TFS (i.e. in the Team Explorer window, connect to the TFS project. You should be able to view work items, etc., but it'll be saying you need to clone the project locally. Now, go to the File menu -> Open -> Project/Solution, and find and open the solution file in your local git repo. If all is good, Visual Studio will keep you still connected to your TFS project, and your solution will be open, and it should remember this in the future (so it should no longer tell you that you have to clone it).

If, on the other hand, Visual Studio disconnected you from the TFS project when you opened the solution (and if you were to reconnect to TFS, it closes the solution), it means it doesn't think they are the same team project. Most likely, this is because the server URL is not 100% the same. Two easy ways this could be is because you might be using different host names or it could be 'http:' vs 'https:'.

Double check this by doing a git remote -v show in your local repo, and compare the URL to what you used in VS when you connected to TFS. Besides the domain name, make sure both are either using "http" or both are "https" (I just had this problem and realized I used 'https' inside Visual Studio, but 'http' when I had previously cloned the repo in git). If they are different, then fix it.

To update the URL in the local git repo:

git remote set-url REMOTE_NAME REMOTE_URL

(substitute the name of your remote for REMOTE_NAME and the url for REMOTE_URL)

(or you could cheat and open .git\config file in a text editor and edit the URLs directly)

Re-open the solution in Visual Studio and see if it kept you connected to TFS. Once Visual Studio sees they are the same server URL, it should remember it, so when you connect to the TFS project using Team Explorer, it shouldn't say you need to clone it first and shortcuts to the solution file(s) should appear (although in VS 2015, I often I have to click the refresh button at the top of Team Explorer when I switch between projects before the solution shortcuts change).

like image 158
DotNetSparky Avatar answered Oct 07 '22 02:10

DotNetSparky


I had the same issue with VS2015 and TFS2015 and my urls were identicals. I fixed the problem by removing the reference to the project in the list of Local Git Repositories. By doing that, the next time I opend the solution, VS2015 "connected" automatically the local repository with TFS2015 Team Project instead of disconnecting me from it and bring me back to the local repository.

Hopes it will help somebody else.

like image 40
mberube.Net Avatar answered Oct 07 '22 02:10

mberube.Net