stephan k
stephan k

Reputation: 631

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

I can't seem to find a way to do this. Is it possible at all? Since this is kind of important in my case, is there a code management platform where this is possible?

Upvotes: 62

Views: 183082

Answers (3)

VonC
VonC

Reputation: 1324268

Instead of switching back and forth between GitHub repository visibility status (which is possible through the repository settings, section "danger zone"), I would rather establish 2 repositories:

  • one public, with only public content
  • one private, with a mix of public and private content

That way, you don't have to wonder, when pushing to a repository, if it is today public or private: you would push to one specific repository (of the two), knowing full well its visibility status.
And you would never expose private content, which, is set to public even a few minutes, ... is no longer ever truly private (because it can be cloned, replicated and pushed elsewhere)


That being said, since June 2020, you have an "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.

See "Setting repository visibility"

https://docs.github.com/assets/images/help/repository/repo-change-select.png

(*) "destructuve action" because of the consequences of the visibility change:

  • public to private: some features won't be available in the repository after you change the visibility to private. Any published GitHub Pages site will be automatically unpublished.
    GitHub Advanced Security features, such as code scanning, will stop working

  • private to public: GitHub will detach private forks and turn them into a standalone private repository


Note that, since July 10th 2020, the default visibility is private:

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.

Upvotes: 60

Swift
Swift

Reputation: 897

Type the name of the repository that you want to make private, for example accountname/reponame. Example : User/Appname so it will enable button to do changes so and so.

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

Upvotes: 0

Lasse V. Karlsen
Lasse V. Karlsen

Reputation: 391336

To switch a repository on GitHub from public to private, or vice versa, follow these instructions:

  1. Go to your repository on GitHub
  2. Go to the "Settings" tab
  3. Scroll all the way down to the section labeled "Danger Zone"
  4. To change the public/private state of the repository:
    1. To make it private: Click the button labeled "Make Private" and follow the instructions
    2. To make it public: Click the button labeled "Make Public" and follow the instructions

Upvotes: 11

Related Questions