main.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 main creates the repo with a branch called main.
git config --global init.defaultBranch main once, then plain git init uses main from now on.
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.
you@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.
you@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.
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.
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.
Run git init -b main for one repo, or run git config --global init.defaultBranch main once so every new repo starts on main.
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.
Your Git version still defaults to master. The message is a hint to set init.defaultBranch, not an error.
The -b option needs Git 2.28 or newer. On older versions run git init, then git branch -m main.