Install Github CLI first
winget install --id GitHub.cli
Login to GitHub in CLI
gh auth login
On github CLI list public repo
gh repo list YOUR_USERNAME --limit 1000 --json nameWithOwner,isPrivate --jq '.[] | select(.isPrivate == false) | .nameWithOwner'
Run Code to make all repos private:
$repos = gh repo list YOUR_USERNAME --limit 1000 --json nameWithOwner,isPrivate --jq '.[] | select(.isPrivate == false) | .nameWithOwner'
foreach ($repo in $repos) {
if ($repo.Trim()) {
Write-Host "Making private: $repo"
gh repo edit $repo `
--visibility private `
--accept-visibility-change-consequences
if ($LASTEXITCODE -eq 0) {
Write-Host "SUCCESS: $repo" -ForegroundColor Green
} else {
Write-Host "FAILED: $repo" -ForegroundColor Red
}
}
}
Verify listing all private
gh repo list YOUR_USERNAME --limit 1000 --json nameWithOwner,isPrivate --jq '.[] | select(.isPrivate == false) | .nameWithOwner'
No comments:
Post a Comment