🌟

WSL2でGit認証を毎回聞かれないようにする

2022/02/15に公開

概要

WSL2環境で快適(かつ安全)にGitを使用できるようにするため、Git Credential Manager for Windowsと、WSLのLinux環境を連携させます。

手順

Git Credential Manager for Windowsをインストールする

  1. 以下のページのDownload and Installlatest installerを選択します。
    https://github.com/microsoft/Git-Credential-Manager-for-Windows#download-and-install

  2. GCMW-{version}.exeのファイルを選択してダウンロードしインストールを実行します。

WSL2(Ubuntu)側のCredential Manager呼び出し設定

Gitのglobal設定のcredential.helperを、Windows側のCredential Managerを使うように設定することで、認証情報を安全に保存できるようになります。

  1. WSL2(Ubuntu)のコンソールで以下コマンドを実行します。
shell
git config --global credential.helper "/mnt/c/Program\ Files/Git/mingw64/libexec/git-core/git-credential-manager.exe"

初回PUSH時に認証情報を聞かれると思います。それ以降、認証情報を入れずに操作できるようになります。

Discussion