Sunday, January 23, 2022

WSL 2.0: Setting up Git on a Windows Subsystem for Linux (WSL) Distribution

In order to run git on a Windows Subsystem for Linux (WSL) distribution, git must be explicitly installed on the distribution. This installation differs from git installed on the host, Windows machine. This post documents the steps required to install and run git on a WSL distribution.

1. Install the git application using sudo apt install git

Once the password for the account with administrative privileges has been entered, git will be installed:

2. Us git config to assign and (obviously use your own name and email address):

git config --global "Jan David Narkiewicz"
git config --global ""

An example of git config invoked to configure name and email is as follows and note that there is no output returned by git config:

3. Install Git Credential Manager (GCM). See section "Appendix A: Git Credential Manager" at the end of this post for more information on GCM. As the name "Git Credential Manager" insinuates, GCM provides authentication support access to git repositories including:
  • for HTTP-enabled Git repositories provides support for single-factor authentication  
  • for ADO (Azure DevOps), Bitbucket, and GitHub support for multi-factor authentication
Git Credential Manager is installed using git config as follows:

git config --global credential.helper "/mnt/c/Program\ Files/Git/mingw64/libexec/git-core/git-credential-manager-core.exe"

An example of git config invoked to configure credential.helper is as follows and note that there is no output returned by git config:

4. Using git with Azure repositories requires the following additional command to be invoked on the terminal for the target WSL distribution:

git config --global credential. true

Once step 3 is completed or when steps 3 and 4 are completed, GCM will manage the credentials git uses so that they do not need to be entered for each git command. To quote Microsoft' excellent write up on setting up Git for WSL (Get started using Git on Windows Subsystem for Linux):

Example of Git Credential Manager 

An example of a git command is being invoked (git clone) is as follows:

If the cached host credentials do not exist or the credentials are invalid, a credential prompt will be displayed:

Closing the Git Credential Manager dialog will fall back on prompting the user for their credentials in the terminal console of the distribution:

Once valid credentials are entered, they will be stored by Git Credential Manager and future git commands will not prompt for credentials. 

Once the credentials are entered on the WSL distribution, GCM is a bridge to Windows Credential Manager on the Windows host. See Windows Credential Manager where a credential exists for

Appendix A: Git Credential Manager

The readme file for Git Credntial Manager can be found on at Git Credential Manager.

No comments :

Post a Comment