Install Github CLI and login via gh auth login
Created
February 18, 2022 21:44
-
-
Save KyleMit/df77840c02c62eefd42be3a1ea4799b0 to your computer and use it in GitHub Desktop.
Rename Default Branch to Main
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# set params | |
$username = 'kylemit' | |
$oldBranch = "master" | |
$newBranch = "main" | |
# get all user repos | |
$repos = gh repo list $username ` | |
--limit 999 --source ` | |
--json nameWithOwner,defaultBranchRef ` | |
--jq '.[].defaultBranchRef |= .name' | | |
ConvertFrom-Json | |
# rename repos w/ oldname to new name | |
$repos | | |
Where-Object defaultBranchRef -eq $oldBranch | | |
ForEach-Object { | |
gh api "repos/$($_.nameWithOwner)/branches/$oldBranch/rename" -f new_name=$newBranch | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment