Git Credential Manager

Learn via video courses
Topics Covered

Overview

Git Credential Manager stores the Git credentials in windows and Linux systems so that the user does not have to enter the credentials every time the user commits. Git credential provides secure storage for the Git credentials.

Pre-requisites

You should have a basic understanding of what is Git and the purpose of using Git.

Introduction to Git Credential Manager

Git credential manager securely stores the Git credentials of the user and provides multi-factor authentication support for Azure DevOps, Github, Gitlab, Bit Bucket, etc.

If you push your commits to a repository you are working on then Git needs to know who is pushing the code changes to the repo. Before pushing the code Git asks for the credentials like username and email for authentication. Instead of providing the credentials every time a push is made, you can store your credentials using Git Credential Manager.

Git Credential Manager is not visible every time a push is made so ideally, the developers forget that he/she is dependent on the Git Credential Manager every time a new push is made to the repo.

Usage

Once the Git Credential Manager for Windows is installed then Git uses the Git Credential Manager to authenticate the user pushing the code to the repository.

Git Credential Manager provides multi-factor authentication. In multi-factor authentication, a user has to provide two or more two verification data to gain access to the resource the user is trying to access.

Commands

In order to interact with the Git Credential Manager the following command is used :

If you are using the newer version of Git then use the following command for Git Credential Manager interactions

Here <command> are the commands used to perform different operations with Git Credential Manager.[<args>] are the other arguments that you need to provide depending upon the command being used.

The different commands used are :

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

This command deploys the Git Credential Manager for the windows package and sets the Git configuration.

  • deploy –path <installation_path> - This command requires the path of the location where Git Credential Manager is to be deployed. If the path is provided then while installing the installer will not ask for any path information from the user.

  • deploy –passive - This command will stop the installer from asking the user for any input while installing the Git Credential Manager. Only error messages can be the output of the installer.

  • deploy –force - This command will neither ask the user for any input nor it will output any error message. It will proceed with the installation even if the prerequisite is not met. Only the return code will be used to validate success.

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

This command is used to remove the Git Credential Manager and unset the Git configuration.

  • remove –path <installation_path> -This command requires the path of the location from where the Git Credential Manager is to be removed. If the path is provided then while installing the installer will not ask for any path information from the user.

  • remove –passive - This command will stop the installer from asking the user for any input while removing the Git Credential Manager. Only error messages can be the output of the installer.

  • remove –force - This command will neither ask the user for any input nor it will output any error message. It will proceed with the removal of Git Credential Manager even if the prerequisite is not met. Only the return code will be used to validate success.

Version

This command shows the current version of the Git Credential Manager.

Version

Install Git Credential Manager

Install Git Credential Manager for Windows

In order to install Git Credential Manager for windows install the latest version of Git for windows which includes the Git Credential Manager with itself.

Make sure to enable Git Credential Manager options if the below dialog box appears while installation.

Install Git Credential Manager for Windows

Install Git Credential Manager for macOS and Linux

On Mac OS X, installing via Homebrew is highly recommended. On Linux, it is recommended to use Linuxbrew or an RPM-based package manager if you can.

You can refer to the Git Credential Manager while installing it on Linux or macOS using the command line.

Using the Git Credential Manager

The Git credential manager will ask for the credentials when you connect with the GitHub repo with the Git client for the first time. You can provide your Microsoft account or Azure credentials which the Git Credential Manager will store. If multi-factor authentication is enabled in your account then the Git Credential Manager will go through the process.

Once the user is authenticated with the provided credentials Git Credential Manager creates and catches a personal access token for future connection to the repo. The Git credential will not pop again until the token gets expires.

Example: Add Git Credentials on Windows

Once you have installed the Git and Git Credential Manager in your system you can set up the Git credentials for the remote server like GitHub, GitLab, Bit bucket, etc.

You have to enter the following command to set up the Git credentials configuration for the remote server.

  • credential.helper - These are Git programs that help you save the Git credentials that help you store your Git credentials in the Git Credential Manager.
  • manager-core - It is the credential manager for Git that helps to authenticate GitHub, GitLab, Bit Bucket, and other remote server access.

To set the user name in the Git Credential Manager run the below command

<username> is the username you have to store in the Git Credential Manager.

To set the email in the Git Credential Manager run the below command

git config –global user.email <email>
eg-// git config –global user.email abc@gmail.com

<email> is the email you have to store in the Git Credential Manager.

You can remove the -global option if you want to set the username and email for a particular repo instead of setting it for all the repos.

Supported Git Versions

Git credential manager is supported in a broader set of Git versions.

All version of Git above 1.9 supports Git Credential Manager.

Conclusion

  • Git Credential Manager securely stores the credential for any remote server like GitHub and bit bucket.

  • Git Credential Manager provides multi-factor authentication support for Azure DevOps, GitHub, GitLab, bit Bucket, etc.

  • To interact with Git Credential Manager git credential-manager-core [<command> [<args>]] command is used.

  • You can store the username in the Git Credential Manager by using the command git config –global user.name <username>

  • You can store the user email in Git Credential Manager by using the command git config –global user.email <email>