Why gh cli create master branch instead of the main branch?

Why gh cli create master branch instead of the main branch?

I was using gh cli to create a new repository and clone immediately to use using the gh repo create <reponame> --public --clone and involuntarily I pushed on the main branch and realized that gh cli has created master instead of the main branch. Why is it not updated to main just as GitHub?

Answer

It needs to be explicit:

gh repo create <reponame> --public --clone --default-branch main

If you want it to be default, run:

gh config set default_branch main

If that does not work then your git settings might be overriding this, which can be changed by the following and then gh will listen:

git config --global init.defaultBranch main

Enjoyed this article?

Check out more content on our blog or follow us on social media.

Browse more articles