Skip to main content

此版本的 GitHub Enterprise Server 已于以下日期停止服务 2024-03-26. 即使针对重大安全问题,也不会发布补丁。 为了获得更好的性能、更高的安全性和新功能,请升级到最新版本的 GitHub Enterprise。 如需升级帮助,请联系 GitHub Enterprise 支持

排查克隆错误

如果您在克隆存储库时遇到问题,请检查这些常见错误。

HTTPS 克隆错误

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

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

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

检查 Git 版本

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

确保远程正确

你要提取的仓库必须存在于 你的 GitHub Enterprise Server 实例 上,且 URL 区分大小写。

可以打开命令行并键入 git remote -v 来查找本地存储库的 URL:

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

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

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

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

提供访问令牌

要访问 GitHub,你必须使用 personal access token 而不是密码进行身份验证。 有关详细信息,请参阅“管理个人访问令牌”。

检查权限

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

提示:如果不想在每次与远程存储库交互时都输入用户名和密码,可以打开凭据缓存。 如果已在使用凭据缓存,请确保您的计算机缓存了正确的凭据。 不正确或过期的凭据将导致身份验证失败。

改用 SSH

如果您以前设置了 SSH 密钥,便可使用 SSH 克隆 URL,而不使用 HTTPS。 有关详细信息,请参阅“关于远程仓库”。

错误:未找到仓库

如果在克隆存储库时看到此错误,这意味着存储库不存在或者你无权访问它,或者 你的 GitHub Enterprise Server 实例 处于专用模式。 此错误有一些解决方案,具体取决于错误原因。

检查拼写

拼写错误可能发生,并且仓库名称区分大小写。 如果尝试克隆 git@HOSTNAME:user/repo.git,但存储库已实际命名为 User/Repo,则会收到此错误。

要避免此错误,克隆时,始终从仓库页面复制和粘贴克隆 URL。 有关详细信息,请参阅“克隆仓库”。

若要更新现有存储库上的的远程存储,请参阅“管理远程仓库”。

检查权限

如果您尝试克隆私有仓库,但没有查看仓库的权限,您将收到此错误。

确保您通过以下方式之一中,拥有仓库的访问权限:

  • 仓库所有者
  • 存储库上的协作者
  • 拥有存储库访问权限的团队成员(如果存储库属于组织)

检查 SSH 访问权限

在极少数情况下,您可能没有仓库的适当 SSH 访问权限。

应确保正在使用的 SSH 密钥已连接到你在 GitHub Enterprise Server 上的个人帐户。 可以通过在命令行中键入以下内容检查此项:

$ ssh -T git@HOSTNAME
> Hi USERNAME! You've successfully authenticated, but GitHub does not
> provide shell access.

有关详细信息,请参阅“将新的 SSH 密钥添加到 GitHub 帐户”。

检查实例是否处于私有模式

如果站点管理员已对你的 GitHub Enterprise 实例启用专用模式,将禁用通过 git:// 进行的匿名克隆。 如果您无法克隆仓库,请联系您的站点管理员。

检查仓库是否确实存在

如果所有其他内容失败,确保仓库在 你的 GitHub Enterprise Server 实例 上确实存在! 如果您尝试推送不存在的仓库,您将收到此错误。

错误:远程 HEAD 引用不存在的 ref,无法检出

如果已在 你的 GitHub Enterprise Server 实例 上删除仓库的默认分支,会发生此错误。

检测此错误很简单;当您尝试克隆以下仓库时,Git 会警告您:

$ git clone https://HOSTNAME/USER/REPO.git
# Clone a repo
> Cloning into 'repo'...
> remote: Counting objects: 66179, done.
> remote: Compressing objects: 100% (15587/15587), done.
> remote: Total 66179 (delta 46985), reused 65596 (delta 46402)
> Receiving objects: 100% (66179/66179), 51.66 MiB | 667 KiB/s, done.
> Resolving deltas: 100% (46985/46985), done.
> warning: remote HEAD refers to nonexistent ref, unable to checkout.

要修复此错误,你需要成为 你的 GitHub Enterprise Server 实例 上仓库的管理员。 你将要更改存储库的默认分支

之后,您可以从命令行获取所有可用分支的列表:

$ git branch -a
# Lists ALL the branches
>   remotes/origin/awesome
>   remotes/origin/more-work
>   remotes/origin/new-main

然后,您可以切换到新分支:

$ git checkout new-main
# Create and checkout a tracking branch
> Branch new-main set up to track remote branch new-main from origin.
> Switched to a new branch 'new-main'