On a recent project, I created a new Git repo and wanted to push my content to the repo from the staging server. You can find a very simple guide on how to do that here.
But as I was trying to push my content to the “existing” repo I was getting this error:
# git push -u origin master
error: src refspec master does not match any.
error: failed to push some refs to 'https://github.com/user/newrepo.git'
I was confused, but then remember seeing this error earlier in the process:
# git commit -m "first commit with content"
On branch master
Initial commit
Untracked files:
assets/
index.html
Turns out, the sequencing provided in the instructions was missing a critical step – Add the files you want to push to the repo after you set the origin.
So a simple fix was to add, then commit the files:
root@test:/var/www/test.net# git add .
root@test:/var/www/test.net# git commit -m "first commit"
[master (root-commit) 9dcbcbd] first commit
135 files changed, 69694 insertions(+)
That should do the trick, and get you the response you’re expecting:
# git push origin master
Username for 'https://github.com':
So if you’re stuck with something similar, try checking that you actually added the files to be committed. 🙂