我们经常发布文档更新,此页面的翻译可能仍在进行中。有关最新信息,请访问英文文档。如果此页面上的翻译有问题,请告诉我们

此版本的 GitHub Enterprise 已停止服务 2021-03-02. 即使针对重大安全问题,也不会发布补丁。 要获得更好的性能、改进的安全性和新功能,请升级到 GitHub Enterprise 的最新版本。 如需升级方面的帮助,请联系 GitHub Enterprise 支持

删除远程

使用 git remote rm 命令可从仓库中删除远程 URL。

本文内容

git remote rm 命令使用一个参数:

  • 远程名称,例如 destination

示例

以下示例假设您使用 HTTPS 克隆,即推荐使用的方法。

$ git remote -v
# 查看当前远程
> origin  https://hostname/OWNER/REPOSITORY.git (fetch)
> origin  https://hostname/OWNER/REPOSITORY.git (push)
> destination  https://hostname/FORKER/REPOSITORY.git (fetch)
> destination  https://hostname/FORKER/REPOSITORY.git (push)

$ git remote rm destination
# 删除远程
$ git remote -v
# 验证其已删除
> origin  https://hostname/OWNER/REPOSITORY.git (fetch)
> origin  https://hostname/OWNER/REPOSITORY.git (push)

git remote rm 不会从服务器中删除远程仓库。 它只是从本地仓库中删除远程及其引用。

疑难解答

当您尝试删除远程时可能会遇到以下错误。

无法删除配置部分 'remote.[name]'

此错误表示您尝试删除的远程不存在:

$ git remote rm sofake
> error: Could not remove config section 'remote.sofake'

检查您是否正确键入了远程仓库的名称。

延伸阅读