Renaming Default Git Branch to 'main'

You can change the default git branch on your local machine to what ever you want. I opted to use 'main' to make it synchronized with the github default. Some other common names are 'trunk', 'prod', and, 'release'.


  • Update your git version to >=2.28

  • Edit your global git config with this command:

    $ git config --global init.defaultBranch main
  • Restart terminal.


For a new project or while learning, I start development locally, initialize git in the directory and make a couple of commits before creating a repo on Github. Recently, I found out having to change the main or trunk branch from "master" to "main" every time there is a need to make a repo is quite repetitive and costs me some milliseconds :D. So for want of a better thing to do, I went searching on the world wide web for how to change the default branch's name.