跳至主要内容

在 GitHub Desktop 中进行 GitHub 身份验证

通过对 GitHub 进行身份验证,您可以在 GitHub Desktop 中安全地访问账户资源。

平台导航

关于身份验证

为保持账户安全,必须先进行身份验证才能使用 GitHub Desktop 访问 GitHub 上的资源。

在进行身份验证之前,您必须已经拥有一个 GitHub 账户。欲了解更多信息,请参阅 在 GitHub 上创建账户

对您的 GitHub 账户进行身份验证

  1. 在菜单栏中,选择 GitHub Desktop,然后单击 设置

    Screenshot of the menu bar on a Mac. Under the open "GitHub Desktop" dropdown menu, the cursor hovers over "Settings", which is highlighted in blue.

  2. 在“设置”窗口的 Accounts(账户)面板中,点击相应的“登录”按钮。使用 Sign Into GitHub Enterprise(登录 GitHub Enterprise)可登录 GitHub Enterprise Server 或具有数据驻留的 GitHub Enterprise Cloud。

    Screenshot of the "Accounts" pane in the "Settings" window. Blue buttons labeled "Sign Into GitHub.com" and "Sign Into GitHub Enterprise" are shown.

  3. 如果您登录的是 GitHub Enterprise 账户,在“登录”模态窗口中,输入访问 GitHub 的 URL,然后点击 Continue(继续)。

  4. 在“使用浏览器登录”模态窗口中,点击 Continue With Browser(使用浏览器继续)。GitHub Desktop 将打开您的默认浏览器。

  5. 在浏览器中进行 GitHub 身份验证,输入您的凭据并点击 Sign in(登录)。

    或者,如果您已登录 GitHub,请按照提示返回 GitHub Desktop 完成身份验证。

  6. 如果您已为 GitHub 配置了双因素身份验证(2FA),请执行以下操作之一

    • 如果您通过短信设置了 2FA,请从短信中获取 2FA 验证码。
    • 如果您使用 TOTP 应用程序设置了 2FA,请生成一个 2FA 验证码。

    随后在 GitHub 的提示框中输入您的 2FA 验证码并点击 Verify(验证)。

  7. GitHub 验证完您的账户后,按照提示返回 GitHub Desktop。

对您的 GitHub 账户进行身份验证

  1. 使用 文件 菜单,然后单击 选项

    Screenshot of the "GitHub Desktop" menu bar on Windows. In the expanded "File" dropdown menu, the "Options" item is outlined in orange.

  2. 在“选项”窗口的 Accounts(账户)面板中,点击相应的“登录”按钮。使用 Sign Into GitHub Enterprise(登录 GitHub Enterprise)可登录 GitHub Enterprise Server 或具有数据驻留的 GitHub Enterprise Cloud。

    Screenshot of the "Accounts" pane in the "Options" window. Blue buttons labeled "Sign Into GitHub.com" and "Sign Into GitHub Enterprise" are shown.

  3. 如果您登录的是 GitHub Enterprise 账户,在“登录”模态窗口中,输入访问 GitHub 的 URL,然后点击 Continue(继续)。

  4. 在“使用浏览器登录”模态窗口中,点击 Continue With Browser(使用浏览器继续)。GitHub Desktop 将打开您的默认浏览器。

    警告

    不支持使用用户名和密码直接对 GitHub 进行身份验证。我们要求通过浏览器进行身份验证。

  5. 在浏览器中进行 GitHub 身份验证,输入您的凭据并点击 Sign in(登录)。

    或者,如果您已登录 GitHub,请按照提示返回 GitHub Desktop 完成身份验证。

  6. 如果您已为 GitHub 配置了双因素身份验证(2FA),请执行以下操作之一

    • 如果您通过短信设置了 2FA,请从短信中获取 2FA 验证码。
    • 如果您使用 TOTP 应用程序设置了 2FA,请生成一个 2FA 验证码。

    随后在 GitHub 的提示框中输入您的 2FA 验证码并点击 Verify(验证)。

  7. GitHub 验证完您的账户后,按照提示返回 GitHub Desktop。

排除身份验证问题

如果 GitHub Desktop 遇到身份验证错误,您可以利用错误信息进行排查。

如果遇到身份验证错误,请先尝试在 GitHub Desktop 上退出账户并重新登录。

对于某些错误,GitHub Desktop 会弹出错误提示。如果未弹出提示,或想获取更多错误信息,请按以下步骤查看 GitHub Desktop 日志文件。

  1. 在菜单栏中选择 Help(帮助),然后点击 Show Logs in Finder(在 Finder 中显示日志)。

    Screenshot of the "GitHub Desktop" menu bar on a Mac. Under the expanded "Help" dropdown menu, "Show Logs in Finder" is highlighted blue.

  2. 选择出现身份验证错误当日的日志文件。

  1. 使用 Help(帮助)下拉菜单,点击 Show Logs in Explorer(在 Explorer 中显示日志)。

    Screenshot of the "GitHub Desktop" menu bar on Windows. In the expanded "Help" dropdown menu, "Show Logs in Explorer" is outlined in orange.

  2. 选择出现身份验证错误当日的日志文件。

查看下面针对您遇到的错误信息的排查指南。

凭据错误

Error: Bad credentials

此错误表示存储的账户凭据存在问题。

排查方法:在 GitHub Desktop 中退出账户后重新登录。

令牌为空

info: [ui] [AppStore.withAuthenticatingUser] account found for repository: node - USERNAME (empty token)

此错误表示 GitHub Desktop 无法在系统钥匙串中找到其创建的访问令牌。

排查方法:在 GitHub Desktop 中退出账户后重新登录。

未找到仓库

fatal: repository 'https://github.com/<user>/<repo>.git' not found

(The error was parsed as 8: The repository does not seem to exist anymore. You may not have access, or it may have been deleted or renamed.)

此错误表示您没有权限访问要克隆的仓库。

排查方法:联系贵组织中负责权限管理的人员。

无法读取远程仓库

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

此错误表示您未设置有效的 SSH 密钥。

排查方法,请参阅 生成新的 SSH 密钥并将其添加到 ssh-agent

克隆失败

fatal: clone of 'git@github.com:<user>/<repo>' into submodule path '<path>' failed
Failed to clone 'src/github.com/<user>/<repo>'. Retry scheduled
Cloning into '<path>'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

此错误表示您尝试克隆的仓库包含您无权访问的子模块,或者您未设置有效的 SSH 密钥。

如果您没有子模块的访问权限,请联系负责该仓库权限的人员进行排查。

如果您未设置有效的 SSH 密钥,请参阅 生成新的 SSH 密钥并将其添加到 ssh-agent

无法读取 AskPass 响应

error: unable to read askpass response from '/Users/<path>/GitHub Desktop.app/Contents/Resources/app/static/ask-pass-trampoline.sh'
fatal: could not read Username for 'https://github.com': terminal prompts disabled

此错误可能由多种情况导致。

如果 Command Processor 注册表项被修改,GitHub Desktop 会返回 Authentication failed(身份验证失败)错误。要检查这些注册表项是否被修改,请按以下步骤操作。

  1. 打开注册表编辑器(regedit.exe),并定位到以下路径:HKEY_CURRENT_USER\Software\Microsoft\Command Processor\ HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor\
  2. 检查上述位置是否存在 Autorun 项。
  3. 如果存在 Autorun 项,请将其删除。

如果您的 Windows 用户名包含扩展的 Unicode 字符,可能导致 AskPass 响应错误。排查方法是创建一个新的 Windows 用户账户并将文件迁移过去。更多信息请参阅 Microsoft 文档中的 在 Windows 中创建用户账户

延伸阅读

© . This site is unofficial and not affiliated with GitHub, Inc.