Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error 400 when cloning TFS Git repo using Visual Studio 2017

In Visual Studio 2017, when I attempt to connect to an existing on-premise TFS 2015 team project, and attempt to clone an existing Git repo using Team Explorer (by clicking the Clone button after highlighting the the repo name in the Connect to a Project modal), I get error message saying

Git failed with a fatal error. fatal: unable to access 'https://servername:8080/tfs/Team Projects Collection/ProjectName/_git/RepoName/': The requested URL returned error: 400

enter image description here

I also get this error showing up in my output window.

like image 756
Steve Kennedy Avatar asked Mar 10 '17 15:03

Steve Kennedy


People also ask

Can we use git to clone from TFS?

Git-tfs also needs to know the path in TFS that you want to clone. It can clone any path (other than the root), so you can clone an entire TFS project, or just one subdirectory of it. Use this command to create a Git repository in local-dir. The new clone includes the full history of $/Project/Path.

What is fatal error in git?

What causes “fatal: not a git repository”? The fatal: not a git repository error makes it clear that you're not in a git repository, but the reason you're not in such a repository may be one of two: 1. You tried to run the command but did not navigate to the project folder where the git repository is located.


2 Answers

UPDATE: It does appear that Microsoft has fixed this issue in an update to Visual Studio 2017. Most likely, Update 3 as mentioned in comment below. If you're not using at least Update 3, this answer may pertain to you still, as people were reporting this issue even with version 15.8.5.


This is primarily because Visual Studio 2017 is mishandling spaces in the Team Project Collection name. It does not encode them to use %20 for spaces. Here's steps to work around.

Click Cancel button to close the "Connect to a Project" window.

In Team Explorer, underneath the Clone Repository section, notice how the top box does have spaces in the URL. Cancel the clone by clicking the Cancel link. Do this, because you'll find that you cannot edit the Clone Repository inputs.

enter image description here

Then, click the Clone Repository link in the Project section of the Team Explorer window.

enter image description here

You'll notice the Clone Repository section will reappear, but now will not be editable. Notice that the first/top input box has replaced any spaces in the URL with %20. Ensure that you're second box, which maps a local path to download your source to, is accurate. Click Clone button, and it should work.

enter image description here

like image 59
Steve Kennedy Avatar answered Oct 29 '22 02:10

Steve Kennedy


I can confirm it is still (or again) broken in version 15.8.1.

But I found another workaround:

  • use a browser to navigate to the 'Code' repository in vsts
  • click on the 'Clone' button (icon)
  • select IDE 'Clone in Visual Studio'
  • allow the link to open VS 2017 and it will pass along the correct url encoded location

enter image description here

like image 20
Ben Pittoors Avatar answered Oct 29 '22 03:10

Ben Pittoors