$ show git-ecosystem/git-credential-manager
Git Credential Manager (GCM) is a production-grade, cross-platform Git credential helper that handles authentication for GitHub, GitLab, Bitbucket, Azure Repos, and generic Git hosts. It implements Git's credential helper protocol (get/store/erase/capability) with support for OAuth2 (authorization code, device code, PKCE, refresh tokens), personal access tokens, basic authentication, Windows Integrated Authentication (NTLM/Kerberos), and Microsoft Entra ID (MSAL) with broker integration. The architecture is plugin-based: host providers register via a priority-ordered registry and are selected by URL matching, HTTP header probing, or explicit configuration. Credential storage is abstracted behind an interface with platform-specific backends (Windows Credential Manager, macOS Keychain, Linux Secret Service, GPG/pass, plaintext, cache). Interactive prompts are delivered via a terminal UI (Spectre.Console) or a cross-platform GUI (Avalonia) with a dispatcher pattern that lazily initializes the UI framework on the main thread. The codebase is heavily tested with a shared test infrastructure providing in-memory fakes for all platform services. Key entry points include Program.cs (process entry), Application.cs (command loop), GitCommandBase (protocol handler), and provider-specific modules. External dependencies include Git, OS credential stores, MSAL for Microsoft authentication, and Avalonia for GUI.
The LLM identified 6 files worth highlighting for reuse:
Implements the OAuth2 authorization code, device authorization grant (RFC 8628), and token refresh flows with PKCE (RFC 7636). Parameterized with server endpoints, client credentials, and response mode. Used by GitHub, GitLab, Bitbucket, and generic providers. Reusable as a standalone OAuth2 client library with minimal adaptation.
Process-wide tracing system implementing Git's TRACE2 event protocol. Supports thread-scoped regions, child process tracking, data/error events, and multiple output formats (stderr, file, named pipe/socket). Includes secret masking and context propagation across async boundaries. Could be extracted as a reusable structured tracing library for any application.
Parses Git configuration output (NUL-delimited) into a cached, scope-aware data structure. Supports URL-scoped lookups (most-to-least specific), type coercion (bool, path), and fallback to per-command git config calls. Handles Git version differences and includes command-line quoting. Reusable for any tool that needs to read Git configuration programmatically.
Implements a lazy-initialization dispatcher pattern for UI frameworks (Avalonia). Posts work from arbitrary threads to a single main-thread loop, preserving execution context and trace regions. Handles startup/shutdown races and framework failure. Reusable for any application that needs to bridge async operations to a UI thread.
In-memory test double that wires all platform service interfaces (IFileSystem, IEnvironment, ISettings, ICredentialStore, IHttpClientFactory, etc.) into a single CommandContext. Used across all test projects to enable deterministic, isolated unit testing of host providers and commands. The pattern of composing test doubles via a context object is reusable for any service-oriented application.
Registry for host providers with priority-based ordering, explicit override by ID/authority, static URL matching, and dynamic HTTP header probing for on-premises instances. Caches probe results and writes provider hints to Git config. Reusable as a generic plugin registry pattern with auto-detection capabilities.