I clone my repository with:
git clone ssh://xxxxx/xx.git
But after I change some files and add
and commit
them,
git show-ref
to see what refs you have. Is there a refs/heads/master
?Due to the recent "Replacing master with main in GitHub" action, you may notice that there is a
refs/heads/main
. As a result, the following command may change fromgit push origin HEAD:master
togit push origin HEAD:main
git push origin HEAD:master
as a more local-reference-independent solution. This explicitly states that you want to push the local ref HEAD
to the remote ref master
(see the git-push refspec documentation).To fix it, re-initialize and follow the proper code sequence:
git init
git add .
git commit -m 'message'
git push -u origin master
It happens if you forget to commit before pushing for the first time. Just run:
git commit -m "first commit"
In my case, I forgot to include the .gitignore
file. Here are all the steps required:
Launch a terminal, and in your project do the following commands:
git remote add origin YOUR/ORIGIN.git
git add .
git commit -m "initial commit or whatever message for first commit"
git push -u origin master
This just mean you forgot to do the initial commit, try
git add .
git commit -m 'initial commit'
git push origin master
git push -u origin master
error: src refspec master does not match any.
For that you need to enter the commit message as follows and then push the code:
git commit -m "initial commit"
git push origin master
Successfully pushed to master.