はじめに
Git Credentialを使用すると, Gitでhttps接続する時のパスワード入力を省略できる.
ただし, 認証情報の保管方法には, 複数のオプションがある.
そのうち, Git Credential Manager (GCM)では, GitHubやBitbucket,
Azure DevOpsの2段階認証に対応している.
GCMはGit for Windowsではデフォルトで使えるが, MSYS2などのGitでは使えない.
使うには, 単純に以下の方法がある.
- MSYSから直接Git for Windowsを使う.
- Git for WindowsのGCMのファイル (exeとdll) をMSYSへコピー.
まず初期設定を確認してみる
Git for Windows
Git for Windowsでは, 以下のとおりデフォルトでGCMを使う設定になっている.
コマンドプロンプト
> git config --show-origin credential.helper
file:C:/Program Files/Git/mingw64/etc/gitconfig manager
MSYS
一方, MSYS2では以下のとおり, credential-manager
(GCM) は使用できない.
MSYS2
$ git credential-manager version
git: 'credential-manager' is not a git command. See 'git --help'.
使うための方法
方法①
MSYSでGCMを使うには, 以下のように直接Git for Windowsを指定して使う.
MSYS
$ /c/Program\ Files/Git/bin/git credential-manager version
Git Credential Manager for Windows version 1.18.4
必要に応じてalias
を設定.
.bashrc
alias wgit=/c/Program\ Files/Git/bin/git
方法②
Git for WindowsにあるGCMのファイルを以下のようにMSYSへコピーする.
MSYS
$ cd /c/Program\ Files/Git/mingw64/libexec/git-core
$ ls -1 git-credential-manager *Authentication* Microsoft.*.dll
AzureDevOps.Authentication.dll
Bitbucket.Authentication.dll
git-credential-manager
GitHub.Authentication.exe
Microsoft.Alm.Authentication.dll
Microsoft.IdentityModel.Clients.ActiveDirectory.dll
$ cp git-credential-manager *Authentication* Microsoft.*.dll /usr/lib/git-core/
ここで, MSYSで再度確認すると, 以下のとおりcredential-manager
が使用できるようになっている.
MSYS2
$ git credential-manager version
Git Credential Manager for Windows version 1.18.4
実際にMSYSでGCMを使用する設定にするには, 以下のとおり.
MSYS
$ git config --global credential.helper manager
参考
確認環境
- Windows 10
- Git for Windows 2.21.0
- MSYS2 (git 2.21.0)