Git Credential Manager for Windows

The Git Credential Manager for Windows (GCM) provides secure Git credential storage for Windows. GCM provides multi-factor authentication support for Visual Studio Team Services, Team Foundation Server, GitHub, and BitBucket.

Usage

After installation, Git will use the Git Credential Manager for Windows and you will only need to interact with any authentication dialogs asking for credentials. The GCM stays invisible as much as possible, so ideally you’ll forget that you’re depending on GCM at all.

Assuming the GCM has been installed, using your favorite Windows console (Command Prompt, PowerShell, ConEmu, etc), use the following command to interact directly with the GCM.

git credential-manager [<command> [<args>]]

Commands

delete

Removes stored credentials for a given URL. Any future attempts to authenticate with the remote will require authentication steps to be completed again.

deploy [--path <installation_path>] [--passive] [--force]

Deploys the Git Credential Manager for Windows package and sets Git configuration to use the helper.

--path <installation_path>

Specifies a path (<installation_path>) for the installer to deploy to. If a path is provided, the installer will not seek additional Git installations to modify.

--passive

Instructs the installer to not prompt the user for input during deployment and restricts output to error messages only.

When combined with --force all output is eliminated; only the return code can be used to validate success.

--force

Instructs the installer to proceed with deployment even if prerequisites are not met or errors are encountered.

When combined with --passive all output is eliminated; only the return code can be used to validate success.

remove [--path <installation_path>] [--passive] [--force]

Removes the Git Credential Manager for Windows package and unsets Git configuration to no longer use the helper.

--path <installation_path>

Specifies a path (<installation_path>) for the installer to remove from. If a path is provided, the installer will not seek additional Git installations to modify.

--passive

Instructs the installer to not prompt the user for input during removal and restricts output to error messages only.

When combined with --force all output is eliminated; only the return code can be used to validate success.

--force

Instructs the installer to proceed with removal even if prerequisites are not met or errors are encountered.

When combined with --passive all output is eliminated; only the return code can be used to validate success.

version

Displays the current version.

clear

Synonym for delete.

install

Synonym for deploy.

uninstall

Synonym for remove.

get / store / erase / fill / approve / reject

Commands for interaction with Git.

Configuration Options

GCM/Askpass work out of the box for most users. Configuration options are available to customize or tweak behavior(s).

The Git Credential Manager for Windows [GCM] can be configured using Git's configuration files, and follows all of the same rules Git does when consuming the files. Global configuration settings override system configuration settings, and local configuration settings override global settings; and because the configuration details exist within Git's configuration files you can use Git's git config utility to set, unset, and alter the setting values.

The GCM honors several levels of settings, in addition to the standard local > global > system tiering Git uses. Since the GCM is HTTPS based, it'll also honor URL specific settings. Regardless, all of the GCM's configuration settings begin with the term credential.

Regardless, the GCM will only be used by Git if the GCM is installed and the key/value pair credential.helper manager is present in Git's configuration.

For example:

credential.microsoft.visualstudio.com.namespace is more specific than credential.visualstudio.com.namespace, which is more specific than credential.namespace.

In the examples above, the credential.namespace setting would affect any remote repository; the credential.visualstudio.com.namespace would affect any remote repository in the domain, and/or any subdomain (including www.) of, 'visualstudio.com'; where as the the credential.microsoft.visualstudio.com.namespace setting would only be applied to remote repositories hosted at 'microsoft.visualstudio.com'.

For the complete list of settings the GCM knows how to check for an apply, see the list below.

Configuration Setting Names

authority

Defines the type of authentication to be used.

Supports Auto, Basic, AAD, MSA, GitHub, Integrated, and NTLM.

Use AAD or MSA if the host is visualstudio.com Azure Domain or Live Account authentication, relatively.

Use GitHub if the host is github.com.

Use BitBucket or Atlassian if the host is bitbucket.org.

Use Integrated or NTLM if the host is a Team Foundation, or other NTLM authentication based, server.

Defaults to Auto.

git config --global credential.microsoft.visualstudio.com.authority AAD

httpProxy

Causes the proxy value to be considered when evaluating credential target information. A proxy setting should established if use of a proxy is required to interact with Git remotes.

The value should the URL of the proxy server.

git config --global credential.github.com.httpProxy https://myproxy:8080

interactive

Specifies if user can be prompted for credentials or not.

Supports Auto, Always, or Never. Defaults to Auto.

git config --global credential.microsoft.visualstudio.com.interactive never

modalPrompt

Forces authentication to use a modal dialog instead of asking for credentials at the command prompt.

Defaults to true.

git config --global credential.modalPrompt true

namespace

Sets the namespace for stored credentials.

By default the GCM uses the 'git' namespace for all stored credentials, setting this configuration value allows for control of the namespace used globally, or per host.

git config --global credential.namespace name

preserve

Prevents the deletion of credentials even when they are reported as invalid by Git. Can lead to lockout situations once credentials expire and until those credentials are manually removed.

Defaults to false.

git config --global credential.visualstudio.com.preserve true

tokenDuration

Sets a duration, in hours, limit for the validity of Personal Access Tokens requested from Visual Studio Team Services [VSTS].

If the value is greater than the maximum duration set for the account, the account value supercedes. The value cannot be less than a one hour (1).

Defaults to the account token duration. Honored by AAD and MSA authorities.

git config --global credential.visualstudio.com.tokenDuration 24

useHttpPath

Causes the path portion of the target URI to considered meaningful.

By default the path portion of the target URI is ignore, if this is set to true the path is considered meaningful and credentials will be store for each path.

Defaults to false.

git config --global credential.bitbucket.com.useHttpPath true

validate

Causes validation of credentials before supplying them to Git. Invalid credentials get a refresh attempt before failing. Incurs some minor overhead.

Defaults to true. Ignored by Basic authority.

git config --global credential.microsoft.visualstudio.com.validate false

writelog

Enables trace logging of all activities. Logs are written to the local .git/ folder at the root of the repository.

Note: This setting will not override the GCM_TRACE environment variable.

Defaults to false.

git config --global credential.writelog true

Sample Configuration

[credential "microsoft.visualstudio.com"]
    authority = AAD
    interactive = never
    preserve = true
    tokenDuration = 12
    validate = false
[credential "visualstudio.com"]
    authority = MSA
[credential]
    helper = manager
    writelog = true

FAQ

If you have an issue using GCM or Askpass, please review the following FAQ and check our issue history or our Twitter feed before opening up an item on our issues page on GitHub.

Q: Why am always prompted for my username and password?

Most likely, your environment is not configured correctly. You can verify that your environment is configured correctly by running git config --list and looking for credential.helper=manager. If you do not see the line, then you know that Git does not know about the Git Credential Manager. You can configure Git to use the Credential Manager by running git config credential.helper manager.

Q: Why does my GUI freeze when I push, pull, or fetch?

Most likely reason is that your GUI “shells out” to git.exe to perform Git operations. When it does so, it cannot respond to the command line prompts for username and password like a real user can. To avoid being asked for your credentials on the command line, and instead be asked via a modal dialog you’ll need to configure the Credential Manager.

  1. Decide if you want this to be a global setting (all of your repositories) or a local setting (just one repository).
  2. Start your favorite shell. (cmd, powershell, bash, etc.)
  3. Update your settings, so that Git Credential Manager knows to display a dialog and not prompt at the command line:

Q: Why am I not seeing my SSH keys being saved?

The Git Credential Manager does not yet support secure storage for SSH keys. It is something we hope to implement, but it has not been a priority. If you feel otherwise, please comment on the SSH Key support issue which is already open.

Q: Is there a NuGet Package available?

Yes there is: https://www.nuget.org/packages/Microsoft.Alm.Authentication. It only supports the core authentication library, but if you're looking to extend the GCM then it is likely exactly what you're after.

Q: Why doesn’t Git Credential Manager work on Windows XP, Mac OS, or Linux?

The Git Credential Manager does not work on Windows XP, Max OS, or Linux because we had to scope our work and we decided to support the same operating systems that Visual Studio support. Why Visual Studio? Well, because it is our favorite IDE and in order to support Visual Studio Team Services we had to use the Azure Directory Authentication Libraries which only have multi-factor interactive logon support in their .NET libraries. Using .NET means using Visual Studio (which we love anyways) and using Visual Studio means Windows 7 or newer.

Q: Will there ever be support for Windows XP, Mac OS, or Linux?

We can safely say that we have no interest in supporting Windows XP. Even Microsoft has ended support for Windows XP. Support for Mac OS and Linux are handled by Microsoft Git Credential Manager for Mac and Linux.

Q: Why is my distribution/version of Git not supported? Why is Git for Windows favored?

The Credential Manager deployment helpers (install.cmd and Setup.exe) are focused on support for Git for Windows because Git for Windows conforms to the expected/normal behavior of software on Windows. It is easy to detect, has predictable installation location, etc. This makes supporting it cheaper and more reliable.

That said, so long as your favorite version of Git supports Git’s git-credential flow, it is supported by the Git Credential Manager for Windows. Setup will have to be manual, and if you find a way to script it we would love to have you contribute that to our project.

  1. Copy the contents of the gcm-<version>.zip to your Git’s /bin folder. This varies per distribution, but it is likely next to other git tools like git-status.exe.
  2. Update your Git configuration by running git config --global credential.helper manager.

Q: I thought Microsoft was maintaining this, why does the GCM not work as expected with TFS?

Team Foundation Server, when deployed on a corporate Active Directory, uses the Microsoft Kerberos protocol for authentication. Git doesn't "speak" the Kerberos protocol.

Git can be convinced to "forward" credentials by supplying a blank credentials (username and password). The GCM will attempt to detect the Team Foundation Server via the HTTP headers returned when an unauthenticated request is handled by the server. If the server is configured to allow NTLM as a supported authentication protocol, the GCM will detect the setting and instruct Git to use NTLM instead of basic authentication.

Alternatively, you can configure the GCM to assume a host supports NTLM without checking. To do so, update your Git configuration by running git config --global credential.my-tfs.integrated true, where my-tfs can be replaced by the name of your TFS server; the port number is not required for GCM configuration but you will want it for the Git remote.

Once updated, the new configuration tells the GCM to only forward domain credentials. If you set credential.integrated true, every domain will be assumed to support domain credentials. Most likely, this is not what you want. Therefore, it strongly suggested that you restrict the configuration setting to the URL of your TFS Git host.

Q: Why doesn't SourceTree use the credentials in the GCM?

You need to configure SourceTree to use the version of Git installed for the entire system. By default, SourceTree uses a local copy of portable Git.

To fix this go to Tools → Options → Git and click the "Use System Git" button. This works in v1.8.3.0 of SourceTree.

Build Agents and Automation

Build agents, and other automation, often require specialized setup and configuration. While there is detailed documentation on GCM configuration options, below are common recommendations for settings agents often require to operate.

Recommendations

Build agents cannot manage modal dialogs, therefore we recommended the following configuration.

git config --global credential.interactive never

Build agents often need to minimize the amount of network traffic they generate.

To avoid Microsoft Account vs. Azure Active Directory look-up against a Visual Studio Team Services [VSTS] account use...

... for Azure Directory backed authentication:

`git config --global credential.authority Azure`

... for Microsoft Account backed authentication:

`git config --global credential.authority Microsoft`

... to restrict the lifetime of VSTS personal access tokens:

`git config --global credential.tokenDuration 1`

If your agents rely on an on premise instance of Team Foundation Server and Windows Domain Authentication, use:

`git config --global credential.authority NTLM`

To avoid unnecessary service account credential validation, when relying on Microsoft Account or Azure Active Directory use:

`git config --global credential.validate false`

Development and Debugging

Developing for GCM and/or Askpass requires Visual Studio 2017 or newer, any version (including the free Community Edition).

Getting Started

The easiest way to get started is to:

  1. Install Visual Studio.
  2. Clone the repository.
  3. Open the solution file (GitCredentialManager.sln) using Visual Studio.
  4. Right-click the solution node in Solution Explorer and choose 'Restore NuGet Packages'. This will download and setup all of the dependencies.
  5. Right-click the 'Cli-CredentialHelper' project in Solution Explorer and select 'Properties'.
  6. In the "Properties" window, select the 'Debug' tab from the left side.
  7. In the "Properties: Debug" window, add the word "get" to the 'Command line arguments:' text box.
  8. Close the "Properties" window.
  9. Hit <F5>, or 'Debug' >> 'Start Debugging' from the top menu of Visual Studio.

Debugging Code

Once the GCM starts you'll be presented with a very unsatisfying console window. This is because the GCM expects to be launched by Git, not directly. However, it is easy to play the role of Git. The GCM expects Git to supply at least two pieces of information: the protocol being use and the host name for which the current operation is happening.

An example of faking Git request for GitHub credentials:

protocol=https
host=github.com
  

Notice the blank last line. That empty line is how Git and the GCM notify the otherside that they're done sending data. Until an empty line is sent to the GCM, it'll keep attempting to read from standard input.

Once the blank line is fed to the GCM it'll "do its thing". Ideally, you can watch it work, so that you can learn how it works and then improve it. To do so, place a break point in the Main method of the 'Program.cs' file. Doing so will allow you to "break in" when the execution pointer reaches your break point. You'll notice that the GCM doesn't read from standard input immediately; instead it does some setup work to determine what it expected of it and then only reads from standard input if it is expected to.

In the case of git credential-manager get, the Main method will call the Get method, which in turn will allocate a new OperationArguments object and initialize it with the process' standard input pipe. This is when standard input will be consumed by the GCM.

Notable Code

Installer (setup.exe)

Changes to the installer (setup.exe) requires Inno Setup Compiler 5.5.9 or later to compile. Additionally, the IDP plugin for Inno Setup is also required.

The setup compiler pulls content from the "Deploy/" folder, therefore a completed Debug or Release build needs to have been completed prior to running the setup compiler. Content in the "Deploy/" folder will be used in the setup compilation.

Microsoft.Alm.Authentication NuGet Package

The Microsoft.Alm.Authentication NuGet package is automatically created when the Microsoft.Alm.Authentication project is built. The generated .nupkg files can be found in the "Debug/" or "Release/" (depending on your build target) under "Microsoft.Alm.Authentication/bin/". Both the binary and symbold packages are automatically created.

Updates to the NuGet package stream are reserved for officially built binaries.

Signing

Only Microsoft can sign binaries with the Microsoft certificate. Therefore, while anyone can build and use their own binaries from the GCM source code, only officially releases binaries will be signed by Microsoft.

Documents

The documentation is formatted using markdown and generated using Pandoc.

Logging

To enable logging, use the following:

`git config --global credential.writelog true`

Log files will be written to the repository's local .git/ folder.

Additionally, the GCM outputs GIT_TRACE compatible logging. To use the GIT_TRACE mechanism you can either:

  1. Open a Command Prompt.
  2. Run SET GCM_TRACE=1; this will cause the GCM to log directly to the console.
  3. If you'd like Git to interleave its traces as well run SET GIT_TRACE=1; now Git will log directly to the console.

Or

  1. Open a Command Prompt.
  2. Run setx GCM_TRACE %UserProfile%\git.log; this will cause the GCM to log to a file located at "%UserProfile%.log".
  3. If you'd like Git to interleave its traces as well run setx GIT_TRACE %UserProfile%\git.log; now Git will log to the file located at "%UserProfile%.log".

Note: The path for logging is arbitrary and both GCM and Git will create/append the file, however neither Git nor the GCM will create any folders; therefore it is up to the user to specify a folder that exists. Additionally, if the specified path contains spaces, be sure to wrap the path in double-quote characters (example: "%UserProfile%git.log"). Finally, inaccessible paths could cause either Git or the GCM to fail unexpectedly, therefor avoid specifying paths which the user's account does not have acccess to; for example paths like "%ProgramFiles%.log" are not recommended because only elevated processes can write to "%ProgramFiles%".

Debug build of the GCM will perform extended logging to the console, which is convenient for debugging purposes bug too noisy for day-to-day usage.

Contribute

There are many ways to contribute.

Code Contributions

For code contributions, you will need to complete a Contributor License Agreement (CLA). Briefly, this agreement testifies that you grant us permission to use the submitted change according to the terms of the project's license, and that the work being submitted is under the appropriate copyright.

Please submit a Contributor License Agreement (CLA) before submitting a pull request. You may visit https://cla.microsoft.com to sign digitally. Alternatively, download the agreement Microsoft Contribution License Agreement.pdf, sign, scan, and email it back to cla@microsoft.com. Be sure to include your GitHub user name along with the agreement. Once we have received the signed CLA, we'll review the request.

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

License

This project uses the MIT License.