Skip to content

Instantly share code, notes, and snippets.

@ben0x539
Created March 20, 2022 02:06
Show Gist options
  • Save ben0x539/fd192087e90ce90e95168f951bef807f to your computer and use it in GitHub Desktop.
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
#!/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