LoginSignup
14
12

More than 1 year has passed since last update.

Git Credential Managerを無理やりMSYSでも使う

Last updated at Posted at 2016-10-02

はじめに

Git Credentialを使用すると, Gitでhttps接続する時のパスワード入力を省略できる.
ただし, 認証情報の保管方法には, 複数のオプションがある.
そのうち, Git Credential Manager (GCM)では, GitHubBitbucket,
Azure DevOpsの2段階認証に対応している.

GCMはGit for Windowsではデフォルトで使えるが, MSYS2などのGitでは使えない.
使うには, 単純に以下の方法がある.

  1. MSYSから直接Git for Windowsを使う.
  2. 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)
14
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
12