Change the default initial branch name in Git

Updated on October 9, 2025

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 main

Subsequent 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=trunk

Note 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:

  1. Sign into your GitHub account.
  2. Click your profile icon in the upper-right corner.
  3. Click Settings
  4. On the side menu, click Repositories under Code, planning, and automation.
  5. Type your preferred default name in the text box.
  6. 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

Why is the default initial branch name usually “master”?

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.

Will changing the default branch name affect existing repositories?

No, this setting only affects new repositories initialized after the change. Existing repositories will retain their current branch names unless you rename them manually.

Is “main” the recommended default branch name now?

Yes. “main” has become the standard default on platforms like GitHub and is widely adopted across the development community for its clarity and neutrality.

Is this change compatible with CI/CD pipelines or deployment scripts?

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

License

Licensed under CC BY 4.0 You are free to share and adapt this content for any purpose as long as you give appropriate credit in a reasonable manner.

No affiliate links

We do not participate in affiliate marketing, and we are not paid to mention products.

Leave a Reply

Your email address will not be published. Required fields are marked *