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.
The short answer
pick oneThis repo only
git init -b main creates the repo with a branch called main.
Every new repo
git config --global init.defaultBranch main once, then plain git init uses main from now on.
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 runyou@laptop my-project % git init
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
Initialized empty Git repository in /Users/you/my-project/.git/
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 commitsyou@laptop my-project % git status On branch master No commits yet you@laptop my-project % git branch -m main you@laptop my-project % git status On branch main No commits yet
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 commandgit 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 littleGit 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.