Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 903
stephan k Avatar asked Sep 07 '19 18:09

stephan k


People also ask

Can I fork a public repo to private github?

Github does not allow a forked repository to be private. This article describes a way to make a private repo that can pull new features of a public repo. The private repo will behave just as a forked repo of the public repo.

Can you make GitHub Pages repo private?

With access control for GitHub Pages, you can restrict access to your project site by publishing the site privately. A privately published site can only be accessed by people with read access to the repository the site is published from.


2 Answers

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.

like image 62
VonC Avatar answered Oct 19 '22 07:10

VonC


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
like image 26
Lasse V. Karlsen Avatar answered Oct 19 '22 06:10

Lasse V. Karlsen