Created
March 20, 2022 02:06
-
-
Save ben0x539/fd192087e90ce90e95168f951bef807f to your computer and use it in GitHub Desktop.
use gh cli to rename default branch from master to main in all your repos
This file contains hidden or 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
#!/usr/bin/env bash | |
set -euo pipefail | |
user=ben0x539 | |
repos=( | |
$( | |
gh repo list --json name,defaultBranchRef --source \ | |
| jq --raw-output '.[] | select(.defaultBranchRef.name == "master") | .name' | |
) | |
) | |
for repo in "${repos[@]}"; do | |
gh api --silent -X POST -H 'Accept: application/vnd.github.v3.raw+json' "repos/$user/$repo/branches/master/rename" -F new_name=main | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment