如何在 GitHub 上将 public 存储库切换为私有存储库,反之亦然?

How can I switch a public repo to private and vice versa on GitHub?

我似乎找不到执行此操作的方法。有可能吗?由于这对我来说很重要,是否有代码管理平台可以做到这一点?

与其在 GitHub 存储库可见性状态(即 possible through the repository settings,“危险区域”部分)之间来回切换,我宁愿建立 2 个存储库:

  • 一个public,只有public个内容
  • 一个私人内容,混合了 public 和私人内容

这样一来,在推送到存储库时,您不必怀疑它是今天 public 还是私有:您将推送到一个特定的存储库(两个),完全了解它的可见性状态。
而且你永远不会公开私有内容,即使几分钟后设置为 public,... 也不再是真正的私有内容(因为它可以被克隆、复制和推送到其他地方)


也就是说,自 2020 年 6 月以来,您有一个“Updated UI for Changing Repository Visibility ”:

You can now set your repository to any available visibility option – public, private, or internal – from a single dialog in the repository's settings.

Previously, you had to navigate separate sections, buttons, and dialog boxes for changing between public and private, and between private and internal.

参见“Setting repository visibility

(*) 由于可见性变化的后果而产生的“破坏性行为”:

  • public 为私有:将可见性更改为私有后,存储库中的某些功能将不可用。任何已发布的 GitHub 页面网站都将自动取消发布。
    GitHub 代码扫描等高级安全功能将停止工作

  • 对 public 私有:GitHub 将分离私有分支并将它们变成独立的私有存储库


请注意,since July 10th 2020默认可见性是私有的

Default visibility for new repositories

When you create a repository, you can choose whether it should be private or public.

Now, when you're signed into GitHub through an organization's single sign on service and create a new repository through the website navigation, the default selection is Private.

This helps prevent sensitive company data from unintentionally being pushed to public repositories. See the about repository visibility article for more information about this choice.

要将 GitHub 上的存储库从 public 切换为私有,反之亦然,请按照以下说明操作:

  1. 前往 GitHub
  2. 上的存储库
  3. 转到 "Settings" 选项卡
  4. 一直向下滚动到标有 "Danger Zone"
  5. 的部分
  6. 要更改存储库的 public/private 状态:
    1. 要将其设为私有:单击标有 "Make Private" 的按钮并按照说明进行操作
    2. 要做到 public:单击标有 "Make Public" 的按钮并按照说明进行操作

键入要设为私有的存储库的名称,例如 accountname/reponame。 示例:User/Appname 因此它将使按钮能够如此这般地进行更改。

参考:https://docs.github.com/en/enterprise/2.19/user/github/administering-a-repository/setting-repository-visibility