LoginSignup
524
502

More than 5 years have passed since last update.

git を https 経由で使うときのパスワードを保存する

Last updated at Posted at 2012-12-26

git を https 経由で使う場合、pull や push のたびに毎回パスワードを聞かれてしまいます。
これを改善するには git-credential を使うと良いです。

git-credential は git 1.7.9 以降で使用可能です。
なお、古いやり方としては .netrc を使う方法もありますが、パスワードを平文でファイルに保存するので、やらないほうがいいと思います。

使用可能な管理方式

git-credential では、以下のような方法でユーザ名とパスワードを管理できます。

  • git-credential-store : ファイルに保存します。ただし、パスワードが平文が保存されます。
  • git-credential-cache : 常駐プロセスに記憶させます。
  • git-credential-osxkeychain : Mac OS X のパスワード管理を使います。
  • Git-Credential-Manager-for-Windows : Windows のパスワード管理を使います。
  • git-credential-gnomekering : GNOME のパスワード管理を使います。

なお、git 本家の contrib に、Windows 用の wincred というものが入っているようです。試していませんが・・・。

cache

cache 方式は標準で付属しています。
次のコマンドで cache 方式が使用できます。

git config --global credential.helper cache

初回パスワード入力時に git-credential-cache--daemon プロセスが常駐して、タイムアウト時間が過ぎるまでパスワードを記憶します。

タイムアウトは、デフォルトでは 900 秒(15分)です。変更するには、次のようにタイムアウト時間(例では 3600 秒)を指定します。

git config --global credential.helper 'cache --timeout=3600'

osxkeychain

osxkeychain は git の contrib として付属しています。MacPorts や Homebrew でインストールすると有効になっています。
次のコマンドで osxkeychain が使用できます。

git config --global credential.helper osxkeychain

初回パスワード入力時に OS X キーチェーンに登録され、以後はパスワード入力が不要になります。

windows

別途インストールが必要です。

手順通りインストールを行えば良いです。

初回パスワード入力時に Internet Explorer などと同じ場所にアクセストークンが保存され、以後はパスワード入力が不要になります。

gnomekeyring

gnomekeyring は別途インストールが必要です。

手順通りビルド・インストールを行えば良いです。

初回パスワード入力時に GNOME キーリングに登録され、以後はパスワード入力が不要になります。

最後に

実は同様のことが github のヘルプにほとんど書いてありました。

524
502
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
524
502