Default Branch

What

Every new Git repository initializes with a default base branch. Historically, Git defaulted to naming this initial branch master. However, modern platforms (such as GitHub and GitLab) and modern Git configurations default to naming the initial branch main.

How

You can configure Git to automatically name the default branch main for all newly initialized repositories. If an existing repository still uses master, you can rename it:

# Set 'main' as the global default branch for future 'git init' commands
git config set --global init.defaultBranch main

# Rename the current active branch in your repository to 'main'
git branch -m master main

Why

Using main as your default branch has become the industry standard. Aligning your local Git default configuration with remote hosting platforms ensures seamless collaboration and prevents synchronization issues when pushing your repositories to the cloud.

Summary

Set init.defaultBranch globally to main to align with modern developer environments, and use the git branch -m <old> <new> command to rename existing branches.