Use gh repo edit OWNER/REPOSITORY --visibility private --accept-visibility-change-consequences to change GitHub repository visibility from the command line. Replace private with public or internal, then run gh repo view --json visibility and verify the result before continuing automation.
GitHub repository visibility guides: Make a repository private · Make a repository public · Use the gh CLI
Prerequisites
Install GitHub CLI and authenticate:
gh auth login
gh auth status
The authenticated account needs repository administrator access. Organization or enterprise policy can still block a visibility change even when the token has broad scopes.
Make a GitHub repository private with gh CLI
gh repo edit OWNER/REPOSITORY \
--visibility private \
--accept-visibility-change-consequences
Make a GitHub repository public with gh CLI
gh repo edit OWNER/REPOSITORY \
--visibility public \
--accept-visibility-change-consequences
Publishing exposes code, Git history, collaboration content, and Actions history. Complete the pre-publication security checklist first.
Make a GitHub repository internal with gh CLI
Internal repositories are available only for eligible enterprise accounts:
gh repo edit OWNER/REPOSITORY \
--visibility internal \
--accept-visibility-change-consequences
Internal means visible to enterprise members; it is not equivalent to private.
Change the current repository
When your shell is inside a local clone, the repository argument is optional:
gh repo edit \
--visibility private \
--accept-visibility-change-consequences
For scripts, specifying OWNER/REPOSITORY is safer because the target is explicit and reviewable.
Verify the change
Do not treat a zero exit code as your only proof. Read the resulting visibility from GitHub:
gh repo view OWNER/REPOSITORY \
--json nameWithOwner,visibility \
--jq '.nameWithOwner + " " + .visibility'
The returned visibility is PUBLIC, PRIVATE, or INTERNAL.
For defensive automation, check the current value before changing it:
gh repo view OWNER/REPOSITORY --json visibility --jq .visibility
This lets a script stop for review when the repository is already in an unexpected state.
Why is the acknowledgement flag required?
GitHub CLI requires --accept-visibility-change-consequences because visibility changes can detach forks, erase stars and watchers, disable rulesets or security features, and expose Actions history and logs. The flag acknowledges those effects; it does not bypass permissions or policy.
Common errors
--accept-visibility-change-consequences is required
Add the flag exactly as shown. GitHub CLI intentionally does not offer a quiet implicit acknowledgement.
HTTP 403 or Resource not accessible
Confirm the authenticated account, repository role, token scopes, organization restrictions, and enterprise repository policy:
gh auth status
gh repo view OWNER/REPOSITORY --json viewerPermission
Internal visibility is unavailable
The repository owner must belong to an enterprise configuration that supports internal repositories. Use private visibility when access should be limited to explicitly granted collaborators.
Official GitHub references
Published August 2026.
