How to Change the Default Git Branch Name to Main (Best Practices for Modern Repositories)

git
Feb 9, 2024

By default, git uses master as the default branch name.

Why Change the Default Git Branch Name?

Historically, Git has used master as the default branch name when initializing new repositories. However, many teams and platforms now recommend or require using main as the default branch for inclusivity and consistency.

How to Set a New Default Branch Name in Git

You can easily change the default branch name for all new repositories you create by configuring Git globally. For example, to use main as the default branch:

git config --global init.defaultBranch main

Note: This feature requires Git version 2.28.0 or newer.

Check your Git version with:

git --version

Summary: Changing the default branch name in Git helps align your projects with modern best practices and platform requirements. Setting main as the default branch is now the standard for new repositories.

Related Articles

Restrict commit to main git branch

Create a pre-commit hook to restrict commits to the main branch.

Multiple GitHub accounts on macOS

Configuring multiple GitHub accounts on same MacBook using ssh keys

Setup Git on Windows

Setting up Git on Windows machine