git-ecosystem/git-credential-manager · error · InvalidOperationException

Cannot determine the organization name for this…

Error message

Cannot determine the organization name for this 'dev.azure.com' remote URL. Ensure the `credential.useHttpPath` configuration value is set, or set the organization name as the user in the remote URL '{org}@dev.azure.com'.

What it means

UriHelpers.CreateOrganizationUri throws this InvalidOperationException when the remote is a dev.azure.com URL but the organization name cannot be extracted: unlike visualstudio.com URLs (org.visualstudio.com), dev.azure.com embeds the org as the first path segment, and if credential.useHttpPath is disabled and the URL has no '{org}@' user info, there is no reliable source for the organization. The library fails loudly rather than guessing.

Solutions

  1. Enable the recommended config: git config --global credential.useHttpPath true (or GCM_SETTING / credential.useHttpPath in the repo).
  2. Embed the organization as the username in the remote URL: git remote set-url origin https://ORG@dev.azure.com/ORG/Project/_git/repo.
  3. Prefer the legacy-style URL form org.visualstudio.com where the org is part of the host, which is unambiguous.
  4. When calling the API directly, pass a dev.azure.com URI whose first path segment is the organization and ensure the request reflects useHttpPath or a remote user.

Example fix

// before
git remote set-url origin https://dev.azure.com/acme/Project/_git/repo  // org not discoverable
// after (either fix works)
git config --global credential.useHttpPath true
git remote set-url origin https://acme@dev.azure.com/acme/Project/_git/repo
Defensive patterns

Strategy: validation

Validate before calling

var uri = new Uri(remoteUri);
if (uri.Host.Equals("dev.azure.com", StringComparison.OrdinalIgnoreCase))
{
    var hasOrgPath = uri.AbsolutePath.Split('/', StringSplitOptions.RemoveEmptyEntries).Length >= 1;
    var hasOrgUser = !string.IsNullOrEmpty(uri.UserInfo);
    var useHttpPath = /* read git config credential.useHttpPath */ hasOrgUser;
    if (!hasOrgUser && !hasOrgPath)
        throw new InvalidOperationException("Set credential.useHttpPath=true or use https://org@dev.azure.com/... so the organization is discoverable.");
}

Type guard

static bool OrganizationIsDiscoverable(Uri remoteUri, bool useHttpPath) =>
    !remoteUri.Host.Equals("dev.azure.com", StringComparison.OrdinalIgnoreCase) // unambiguous host forms
    || !string.IsNullOrEmpty(remoteUri.UserInfo)                                  // {org}@dev.azure.com
    || useHttpPath;                                                                // org taken from http path

Try / catch

try { return UriHelpers.GetOrganizationName(remoteUri); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Cannot determine the organization name"))
{
    // prompt user to enable credential.useHttpPath or add {org}@ to the remote URL
    return null;
}

Prevention

When it happens

Trigger: Calling GetOrganizationName on a URL like https://dev.azure.com (or one whose first path segment is missing/unusable) when credential.useHttpPath is not enabled and the remote URL carries no username ('{org}@dev.azure.com') from which to read the organization.

Common situations: Very short dev.azure.com URLs like https://dev.azure.com/org that GCM's URL trimming normalizes past the org segment; users migrating from org.visualstudio.com URLs to dev.azure.com without enabling useHttpPath; tooling constructing bare https://dev.azure.com URIs programmatically; GCM_HINT/GCM settings lacking credential.useHttpPath=true.

Understand the failure class

Background: "missing required config value" errors: why libraries refuse to start when a configuration key is empty, unset, or blank — this error's family across 48 libraries.

Related errors


AI-assisted analysis of git-ecosystem/git-credential-manager@e8ce762cd0 (2026-09-11). Data as JSON: /api/errors/4ba00cd29af4e1ed. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.AzureRepos/UriHelpers.cs:165

            // The older *.visualstudio.com URLs contained the organization name in the host already.
            if (IsDevAzureComHost(remoteUri.Host))
            {
                string firstPathComponent = GetFirstPathComponent(remoteUri.AbsolutePath);
                string remoteUriUserName = remoteUri.GetUserName();

                // Prefer getting the org name from the path: dev.azure.com/{org}
                if (!string.IsNullOrWhiteSpace(firstPathComponent))
                {
                    orgName = firstPathComponent;
                }
                // Failing that try using the username: {org}@dev.azure.com
                else if (!string.IsNullOrWhiteSpace(remoteUriUserName))
                {
                    orgName = remoteUriUserName;
                }
                else
                {
                    throw new InvalidOperationException(
                        "Cannot determine the organization name for this 'dev.azure.com' remote URL. " +
                        "Ensure the `credential.useHttpPath` configuration value is set, or set the organization " +
                        "name as the user in the remote URL '{org}@dev.azure.com'."
                    );
                }

                ub.Path = orgName;
            }
            else if (IsVisualStudioComHost(remoteUri.Host))
            {
                // {org}.visualstudio.com
                int orgNameLength = remoteUri.Host.Length - AzureDevOpsConstants.VstsHostSuffix.Length;
                orgName = remoteUri.Host.Substring(0, orgNameLength);
            }

            return ub.Uri;
        }

View on GitHub (pinned to e8ce762cd0)