git: rename local branch failed git: rename local branch failed git git

git: rename local branch failed


I get into this issue too. The reason is that I didn't have any commit on this git repository.

When I run the command git branch -M main. I get the following error message.

error: refname refs/heads/master not foundfatal: Branch rename failed

After I add my first commit by the following command, all things works.

git add .git commit -m 'Init'


You are currently in detached head state. You must checkout a new branch to associate it with the current commit:

git checkout -b new_branch


I thought it was a conflict of "git init" creating master branch and github's (new) "main".

After:

git add .git commit -m "first commit" 

I was able to git branch -M main

enter image description here