error: src refspec main does not match any [GIT]

Updated on December 21, 2021

Created a private repository on GitHub and when tried to push the files from my server using the below commands, I get error: src refspec main does not match any.The complete command and error are as below:

# git add . 
# git commit -m "Initial Commit"
# git push origin main

I also used the token as per the latest git policy but didn’t work and got the below error message:

error: src refspec main does not match any.
error: failed to push some refs to 'https://ghp_....ROGL....RxUje@github.com/XXXX/XXX.git'

How to solve git error: src refspec main does not match any

Starting from October 1st, GitHub renamed master branch to main and all new repositories will create the default branch named main. Well, if you are curious to know why this change, then here’s an article explaining the reason.

Lets check the local reference head using the below command.

$ git show-ref 
95b095fb6dd8c8af48c35317af7da14bd9f9f622 refs/heads/master

The output of the above command says that the local is still refering to master head and not the newly renamed main.

To change the local reference to point to main branch, replace HEAD:master with HEAD:main in the below command.

# git push origin HEAD:master

to

# git push origin HEAD:main

The above command states that you want to push the local ref HEAD to the remote ref main.

That’s it!

Was this article helpful?

Related Articles

Comments Leave a Comment

Leave a Comment