1

I get this error when trying to clone a repository from Azure Devops in Visual Studio 2019 :

TF401019: The Git repository with name or identifier X does not exist or you do not have permissions for the operation you are attempting.
Error encountered while cloning the remote repository: Git failed with a fatal error.

I'm using two accounts :

  • user@domain.com
  • user@seconddomain.com

user@domain.com is my main account in visual studio, it has access to my repo, but no rights. user@seconddomain.com is another account setup in visual studio, it has full access to my repo.

When I try to clone the repo, I get the error above. In Azure Devops, I noticed that a personal access token is created in my first account and not in my second account, so I'm assuming that it's trying to connect with the wrong account. I never get asked for credentials from Visual studio, even when I delete the credentials from the Windows Credentials Manager and clear the cache from IE and Edge.

Is there a way to specify under which account to clone an Azure Devops repository in Visual Studio 2019?

---- Update

When I'm cloning, I'm logged in with account #2 in visual studio and listing repos under dev.azure.com

enter image description here

But I get this error :

Remote: TF401019: The Git repository with name or identifier X does not exist or you do not have permissions for the operation you are attempting.
Error encountered while cloning the remote repository: Git failed with a fatal error.
repository 'https://dev.azure.com/X' not found

And then, in Azure Devops, with account #1, a PAT is created enter image description here

The PAT gets stored in the Windows Credentials Manager (I delete it for each try) enter image description here

Phil-R
  • 2,193
  • 18
  • 21
  • Any update for this issue? Have you resolved this issue? If not, would you please let me know the latest information about this issue? – Leo Liu May 13 '20 at 09:52

2 Answers2

1

Is there a way to specify under which account to clone an Azure Devops repository in Visual Studio 2019?

Sorry for any inconvenience.

This behavior is by designed. We could not specify another account to clone an Azure Devops repository in Visual Studio.

When we connect the repo from the Visual Studio, it prompts for login account instead of entering authentication information:

enter image description here

If we want to specify another account to clone the repo, we need to keep two more credentials in Visual Studio. When we are in the process of synchronizing VS with Azure devops, VS cannot intelligently choose which certificate to use for authentication, otherwise we must manually select the certificate each time we synchronize the code.

On the other side, we could not specify another account in the login account, which may involve the issue of overrun (low-privilege accounts use high-privilege accounts).

That the reason why visual studio lets us use a login account as authentication.

If you want to use another account to clone the code from repo, you could try to use the command line and PAT, like:

git clone https://<PAT>@dev.azure.com/<OrganizationName>/YourProject/_git/..

Username nor password should not be required as the PAT should suffice.

Hope this helps.

Community
  • 1
  • 1
Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • 1
    Thanks for your answer, the PAT approach in the URL does work, so it's a nice workaround. As for the "Connect to a project" window, I do login with the right account, it's listing the right repos, but when I try to clone, it's cloning with the wrong account. Is that the behavior you are describing? – Phil-R May 06 '20 at 12:51
  • 1
    I know it's cloning with the wrong account because, as I stated in the post, I get an error in visual studio and a PAT is created under the wrong account each time I clone. I will update the post with screenshots to detail further. – Phil-R May 07 '20 at 13:14
  • @Phil-R, Sorry for my late reply, I just got out of other threads. According to your reply, it seems the issue comes from the Visual Studio, if you can clone with the PAT in the command line. So, we could try to clean the cache for Visual Studio, like using `devenv /resetuserdata` command in the VS Developer Command Prompt as an Administrator. Or Clear the config from the following path: `C:\users\\AppData\Roaming\Microsoft\VisualStudio\15.0_????\Team Explorer\`, even we can test it on other PC. – Leo Liu May 11 '20 at 09:30
0

I'm assuming Windows?
VS may be falling back to the wrong identity, I don't think there is a way to force VS to use certain account over the other. I suggest you clone from the command line. VS has its own Git client so it handles identities outside git credential manager which will ask for credentials if it cannot find one within Windows credential manager.

MS support would suggest the following though not sure it will work:

Try signing out and forget your accounts. Remove caches. VS Identities are cached in the following paths for windows.

C:\Users\{user}\AppData\Local\.IdentityService
C:\Users\{user}\AppData\Local\Microsoft\Team Foundation\{each version}\Cache
C:\Users\{user}\AppData\Local\Microsoft\Team Foundation\{each version}\Cache
C:\Users\{user}\AppData\Local\Microsoft\VisualStudio Services\{each version}\Cache
C:\Users\{user}\AppData\Local\GitCredentialManager\tenant.cache

Also clean your Windows credential manager entries that begin with git:*.

After following these steps I would expect git to ask for credentials if you clone from the command line.

Aram Maliachi
  • 215
  • 2
  • 8
  • Thanks, it does ask for credentials after I clean these caches, but even though I log with the right account, the clone still creates a PAT for the wrong account – Phil-R May 06 '20 at 12:52