I have been looking for a way to change the default branches of a bunch of my repositories (>50). Thus I am trying to make a bash script to do it for me.
However every answer I find, e.g. Deleting remote master branch, refused due to being the current branch, tells me to "go to the setting page on GitHub".
Can you do it without the UI?
You can do it directly with the gh repo edit
command of the GitHub CLI like this:
gh repo edit {owner}/{repo} --default-branch main
or if you have set a default remote repository, you can execute the command in the local repository without specifying the owner & repository:
gh repo edit --default-branch main
Please note that the new default branch must already exist, otherwise there will be a validation error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With