文章版本: Enterprise Server 2.17
在 Git 中缓存 GitHub 密码
如果使用 HTTPS 克隆 GitHub 仓库,您可以使用凭据小助手告诉 Git 在每次与 GitHub 会话时记住您的 GitHub 用户名和密码。
如果使用 SSH 克隆 GitHub 仓库,则应使用 SSH 密钥进行身份验证,而不是使用用户名和密码。 有关设置 SSH 连接的帮助信息,请参阅生成 SSH 密钥。
提示:
- 您需要 Git 1.7.10 或更高版本才能使用 osxkeychain 凭据小助手。
- 如果您使用 Homebrew 安装了 Git,则已经安装了
osxkeychain 助手
。 - 如果您运行 Mac OS X 10.7 及更高版本,并且通过 Apple 的 Xcode 命令行工具安装了 Git,则
osxkeychain 助手
自动包含在您的 Git 安装中。
安装 Git 和 osxkeychain 助手
并告诉 Git 使用它。
-
核实是否已安装 Git 和
osxkeychain 助手
:$ git credential-osxkeychain # Test for the cred helper > Usage: git credential-osxkeychain <get|store|erase>
-
If the
osxkeychain helper
isn't installed and you're running OS X version 10.9 or above, your computer will prompt you to download it as a part of the Xcode Command Line Tools:$ 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.
Alternatively, you can install Git and the
osxkeychain helper
by using Homebrew:$ brew install git
-
Tell Git to use
osxkeychain helper
using the globalcredential.helper
config:$ git config --global credential.helper osxkeychain # Set git to use the osxkeychain credential helper
The next time you clone an HTTPS URL that requires a password, you'll be prompted for your username and password, and to grant access to the OSX keychain. 完成此操作后,用户名和密码将存储在您的密钥链中,您不需要在 Git 中再次键入它们。