Skip to content

Instantly share code, notes, and snippets.

@ohader
Created November 29, 2021 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ohader/4238d8789cced2083f9881526dee72c3 to your computer and use it in GitHub Desktop.
Save ohader/4238d8789cced2083f9881526dee72c3 to your computer and use it in GitHub Desktop.
Rename Git master to main branch via GitHub API
#!/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