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?
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:
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"
(*) "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.