Say a daring developer wishes to undertake the simple (and recommended) task of renaming their repositories master branch to main. Should be simple right?
Such a developer thus grabs the latest changes from master, renames the branch, fetches the upstream and moves the origin. Something along the lines of this:
git pull origin master
git branch -m master main
git fetch origin
git branch -u origin/main main
Swell.
Now, however, the piece of advice that every website recommends is to escape the comfort of your terminal and venture to your web browser and, (dare I say it) click to change the default branch.
Easy some might say, however, in the cases of organizations with multiple repositories, this doesn't scale well. Assuming that all of the recommended checks are in place and every repository is ready to be renamed:
How then might the remote master branch be deleted such that you could pack the whole process in a short script and automate it all without having to go to the web browser?
Such a developer might naively think to try to delete the remote master branch like any other remote branch with:
git push origin --delete master
But the master branch (or whatever the default branch was named as) is not like other branches. It's protected, and thus this will result in error: failed to push some refs to 'https://github.com/username/repo-name.git'.
Moreover, we just renamed master
Constraints: Web API is fair game, Github CLI / API is fair game, basically anything that could run on a headless server without access to a web GUI, and all history should be maintained (Thanks!)