简体   繁体   中英

Using multiple accounts to access Azure Devops Git repo from Visual Studio

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

在此处输入图像描述

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 在此处输入图像描述

The PAT gets stored in the Windows Credentials Manager (I delete it for each try) 在此处输入图像描述

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:

在此处输入图像描述

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM