长期存储git的http密码:
git config --global credential.helper store
核实是否已安装 Git 和 osxkeychain 助手
:
$ git credential-osxkeychain
# Test for the cred helper
> Usage: git credential-osxkeychain <get|store|erase>
如果 osxkeychain helpper
尚未安装,而您使用的是 OS X 10.9 或更高版本,您的计算机会提示您将其下载为 Xcode Command Line 工具的一部分:
$ git credential-osxkeychain
> xcode-select: note: no developer tools were found at '/Applications/Xcode.app',
> requesting install. Choose an option in the dialog to download the command line developer tools.
或者,您也可以使用 Homebrew 安装 Git 和 osxkeychain helper
:
$ brew install git
- 使用 global
credential.helper
config 指示 Git 使用osxkeychain helper
:
$ git config --global credential.helper osxkeychain
# Set git to use the osxkeychain credential helper
下次克隆需要身份验证的 HTTPS URL 时,Git 会提示您输入用户名和密码。 当 Git 提示您输入密码时,请输入您的个人访问令牌 (PAT)。 基于密码的身份验证对 Git 已弃用,使用 PAT 更安全。
验证成功后,您的凭据存储在 macOS 密钥链中,每次克隆 HTTPS URL 时都会使用。 除非更改凭据,否则无需在 Git 中再次键入凭据。