阅读(260) (0)

GitHub HTTPS 克隆错误

2020-08-19 14:38:34 更新

对 Git 使用 HTTPS 时有几种常见错误。 这些错误通常表示您有旧版 Git,或无法访问仓库。

下面是您可能收到的 HTTPS 错误示例:

> error: The requested URL returned error: 401 while accessing
> https://github.com/user/repo.git/info/refs?service=git-receive-pack
> fatal: HTTP request failed
> Error: The requested URL returned error: 403 while accessing
> https://github.com/user/repo.git/info/refs
> fatal: HTTP request failed
> Error: https://github.com/user/repo.git/info/refs not found: did you run git
> update-server-info on the server?

检查 Git 版本

与 GitHub 交互没有最低 Git 版本要求,但我们发现 1.7.10 版是一个方便、稳定的版本,适用于许多平台。 您可随时在 Git 网站上下载最新版本

确保远程正确

您要提取的仓库必须存在于 GitHub 上,且 URL 区分大小写。

您可以打开命令行并输入 git remote -v 来查找本地仓库的 URL:

$ git remote -v
## View existing remotes
> origin  https://github.com/github/reactivecocoa.git (fetch)
> origin  https://github.com/github/reactivecocoa.git (push)


$ git remote set-url origin https://github.com/github/ReactiveCocoa.git
## Change the 'origin' remote's URL


$ git remote -v
## Verify new remote URL
> origin  https://github.com/github/ReactiveCocoa.git (fetch)
> origin  https://github.com/github/ReactiveCocoa.git (push)

也可通过 GitHub Desktop 应用程序更改 URL。

提供访问令牌

要访问 GitHub,您必须使用个人访问令牌而不是密码进行身份验证。 更多信息请参阅“创建个人访问令牌”。

如果要访问使用 SAML SSO 的组织,您在进行身份验证之前还必须授权个人访问令牌访问组织。 更多信息请参阅“关于使用 SAML 单点登录进行身份验证”和“授权个人访问令牌用于 SAML 单点登录”。

检查您的权限

提示输入用户名和密码时,确保使用可以访问仓库的帐户。

提示:如果不想在每次与远程仓库交互时都输入用户名和密码,您可以打开凭据缓存

改用 SSH

如果您以前设置了 SSH 密钥,便可使用 SSH 克隆 URL,而不使用 HTTPS。 更多信息请参阅“我应使用哪个远程 URL?