How to Switch a GitHub Repository from Public to Private via CLI
Developers sometimes need to restrict access to a GitHub repository that was initially made public, particularly when it contains sensitive business logic, credentials, or internal configurations. GitHub CLI (gh) allows users to change a repository's visibility directly from the terminal using the command 'gh repo edit' with the '--visibility private' and '--accept-visibility-change-consequences' flags. The additional flag is mandatory because GitHub warns that visibility changes can affect forks, watchers, stars, and third-party integrations. Once the change is applied, visibility can be confirmed by running 'gh repo view --json visibility', which should return 'PRIVATE'. Importantly, making a repository private does not erase previously exposed secrets, so any leaked API keys or tokens must be rotated immediately.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in