Skip to content

Instantly share code, notes, and snippets.

@KyleMit
Created February 18, 2022 21:44
Show Gist options
  • Save KyleMit/df77840c02c62eefd42be3a1ea4799b0 to your computer and use it in GitHub Desktop.
Save KyleMit/df77840c02c62eefd42be3a1ea4799b0 to your computer and use it in GitHub Desktop.
Rename Default Branch to Main
# 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