When I ran git branch -m master main
before having made any commits, I got this error:
error: refname refs/heads/master not found
fatal: Branch rename failed
Git needs there to be at least one commit on the branch before you can work with it in this way. See this related question: git: rename local branch failed.
Do the initial commit:
$ git add -A
$ git commit -m "Initial commit"
Then the accepted answer works:
$ git branch -m master main
$ git status
On branch main
nothing to commit, working tree clean