Git assigns a name to the initial branch when creating a repository. Historically, the default name is master. As of Git 2.28, you can specify a different default name with the following command:
# The following command changes the default name to "main"
git config --global init.defaultBranch mainSubsequent calls to git init will now use the default name unless the branch name is explicitly specified. To explicitly 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=trunkNote that existing repositories are not impacted by changing the default initial name.
Changing the default branch name on GitHub
GitHub allows you to create repositories through the web interface. You can set your preferred initial branch name with these steps:
- Sign into your GitHub account.
- Click your profile icon in the upper-right corner.
- Click Settings
- On the side menu, click Repositories under Code, planning, and automation.
- 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.
Frequently Asked Questions
Historically, Git used “master” as the default branch name when initializing a new repository. This naming convention dates back to early software development practices but has come under scrutiny for its lack of inclusivity. Many platforms, including GitHub, now default to “main” instead.
No, this setting only affects new repositories initialized after the change. Existing repositories will retain their current branch names unless you rename them manually.
Yes. “main” has become the standard default on platforms like GitHub and is widely adopted across the development community for its clarity and neutrality.
Yes, but you’ll need to update any scripts or configuration files that reference the old branch name. This includes .yml files for GitHub Actions, deployment tools, and build systems.
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