[Solved] Git error: refname refs/heads/master not found

Problems encountered

Create a project and associate it to a git remote warehouse

$ git init
$ git remote add origin [email protected]:abeelan/vue_demo.git
$ git branch -M main
$ git push -u origin main

Execute the third line of command, and an error occurs when changing the branch name

error: refname refs/heads/master not found
fatal: Branch rename failed

Solution:

$ git init
$ git remote add origin [email protected]:abeelan/vue_demo.git
$ git add .
$ git commit -m "demo finished"
$ git branch -M main
$ git push -u origin main

To modify the branch name, you need to have a commit before you can change it.

Read More: