Skip to main content

在 GitHub Desktop 中向 GitHub 进行身份验证

可以通过向 GitHub 验证来安全地访问您的帐户在 GitHub Desktop 上的资源。

Platform navigation

关于身份验证

为确保帐户安全,必须先进行身份验证,然后才可使用 GitHub Desktop 访问 GitHub 上的资源。

在进行身份验证之前,必须在 GitHub 上拥有帐户。有关详细信息,请参阅 在 GitHub 上创建帐户

对 GitHub 帐户进行身份验证

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

    Windows 上的“GitHub Desktop”菜单栏的屏幕截图。 在展开的“文件”下拉菜单中,以橙色框出了“选项”项。

  2. 在“选项”窗口中的“帐户”窗格中,单击相应的“登录”按钮****。 使用“登录到 GitHub Enterprise”登录到 GitHub Enterprise Server 或 具有数据驻留的 GitHub Enterprise Cloud****。

    “选项”窗口中“帐户”窗格的屏幕截图。 会显示标记为“登录到 GitHub.com”和“登录到 GitHub Enterprise”的蓝色按钮。

  3. 如果你正在登录 GitHub Enterprise 上的帐户,在“Sign in”模式窗口中,键入你访问 GitHub 的 URL,然后单击“Continue”****。

  4. 在“使用浏览器登录”模型窗口中,单击“继续使用浏览器”。 GitHub Desktop 将打开您的默认浏览器。

    Warning

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

  5. 若要向 GitHub 进行身份验证,请在浏览器中键入凭据并单击“登录”****。

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

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

    • 如果通过 SMS 设置 2FA,则从 SMS 消息检索 2FA 代码 。
    • 如果使用 TOTP 应用程序设置 2FA,则生成 2FA 代码。

    然后在 GitHub 的提示中输入你的 2FA 代码,然后单击“验证”。

  7. 在 GitHub 对帐户进行身份验证后,按照提示返回到 GitHub Desktop。

排查身份验证问题

如果 GitHub Desktop 遇到身份验证错误,可以使用错误消息进行故障排除。

如果您遇到身份验证错误,请先尝试在 GitHub Desktop 上注销您的帐户,然后重新登录。

对于某些错误,GitHub Desktop 会以错误消息提示您。 如果没有提示,或者要查找任何错误的更多信息,请使用以下步骤查看 GitHub Desktop 日志文件。

  1. 使用“帮助”下拉菜单,然后单击“在 Explorer 中显示日志” 。

    Windows 上的“GitHub Desktop”菜单栏的屏幕截图。 在展开的“Help”下拉菜单中,“Show Logs in Explorer”以橙色标出。

  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 中创建用户帐户”。

其他阅读材料