Change the default initial branch name in Git

Updated on September 21, 2025

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.

  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 the Code, planning, and automation section.
  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.

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 *