Git assigns a name to the initial branch when creating a repository. Historically, the default is master. As of Git 2.28, you can specify a different default name with the following command:
# change default to "main"
git config --global init.defaultBranch main
Subsequent calls to git init
will now use the default name unless the branch name is explicitly specified. To specify a name, you can use the -b
or --initial-branch
parameter:
# set the initial branch name with the -b parameter
git init -b trunk
# Alternately, you can use --initial-branch (both are equivalent)
git init --initial-branch=trunk
Note that existing repositories are not impacted by changing the default name. For existing repositories, you can rename branches.
Changing the default branch name on GitHub
On GitHub, you can change the default branch name for repositories created through GitHub rather than your computer.
- Sign into your GitHub account.
- Click your profile icon in the upper-right corner.
- Click Settings
- On the side menu, click Repositories under the Code, planning, and automation section.
- Type your preferred default name in the text box.
- Click Update to save your preference.
After doing this, new repositories created through GitHub will use your preferred name for the initial branch.
Reference
- Highlights from Git 2.28 – The GitHub Blog – Introduces the init.defaultBranch setting to change the default name of the initial branch.
- Regarding Git and Branch Naming – Software Freedom Conservancy – explanation of the motivation behind the move from master to main.
Leave a Reply