Created
November 29, 2021 11:31
-
-
Save ohader/4238d8789cced2083f9881526dee72c3 to your computer and use it in GitHub Desktop.
Rename Git master to main branch via GitHub API
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
#!/bin/bash | |
# | |
# replace `GITHUBTOKEN` with custom token from https://github.com/settings/tokens, having `repo` admin access | |
# | |
for repo in $(curl -s -H "Authorization: token GITHUBTOKEN" 'https://api.github.com/orgs/TYPO3-CMS/repos?per_page=100' | jq -r '.[] | .url' | sort) | |
do | |
echo "Renaming ${repo}..." | |
response=$(curl -s -X POST \ | |
-H "Authorization: token GITHUBTOKEN" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
${repo}/branches/master/rename \ | |
-d '{"new_name":"main"}') | |
name=$(echo ${response} | jq -r '.name') | |
if [ "${name}" == "main" ] | |
then | |
echo "OK: ${name}" | |
else | |
echo "FAILED" | |
echo ${response} | |
fi | |
echo | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment