Changing the default branch name in Git
In older versions of Git, the name of the branch created on running the git init
command was called master
. In some versions of Git, you will see a warning that this default branch name is bound to change in future.
Git also suggests some better alternative names that can be used for the default branch like main, trunk or development.
Let's say that you want to change the name of the default branch to main
. In order to do so, you can run the command:
git branch -m main
This changes the default branch name to main:
In order to initialize Git repositories in the future with main
as the default branch name, you can set a configuration as follows:
git config --global init.defaultBranch main
With this configuration, when you create new Git repositories in the future, the default branch name will be main
.