FIX · HOW TO

Start with main.
Not master.

You ran git init and Git printed a long hint about "master". Here is how to get main from the start, and how to rename it if you already ran init.

git init -b maininit.defaultBranchgit branch -m

The short answer

pick one
1

This repo only

git init -b main creates the repo with a branch called main.

2

Every new repo

git config --global init.defaultBranch main once, then plain git init uses main from now on.

3

Already ran init

git branch -m main renames the current branch. It works before your first commit and after.

-b needs Git 2.28 or newer. Run git --version if it is rejected. On older Git, use option 3.

What you saw

the hint, from a real run

That is a hint, not an error. Older Git defaults to master. Newer Git versions may default to main and print nothing. It depends on your Git version and your config.

Rename the branch you have

before or after commits

After you have made a commit, the same command renames the branch and keeps your history. git branch then lists * main. If you already pushed master to GitHub, renaming locally does not rename the remote branch. Push main as a new branch and change the default branch in the repository settings on GitHub.

Check what your config says

one command

git config --global --get init.defaultBranch prints the name you set. If it prints nothing, you have not set one and Git uses its built-in default. Setting it only affects repositories you create afterwards. Existing repos keep their branch names.

Why does the name matter?

only a little

Git does not care what the first branch is called. GitHub now creates new repositories with main, so using the same name locally keeps your first git push simple. Nothing breaks if you keep master, as long as you push the branch name you actually have.

Questions people ask

How do I create a Git repo with main as the default branch?

Run git init -b main for one repo, or run git config --global init.defaultBranch main once so every new repo starts on main.

How do I rename master to main in Git?

Run git branch -m main while on the master branch. It works with or without commits. If master is already on GitHub, push main and change the default branch in the repo settings.

Why does git init say Using master as the name for the initial branch?

Your Git version still defaults to master. The message is a hint to set init.defaultBranch, not an error.

Does git init -b work on old Git?

The -b option needs Git 2.28 or newer. On older versions run git init, then git branch -m main.

Git, Visually · Parts 1 and 2 · English