Two possible causes:
- Cloned the repository with
$ git clone ssh://project-url/rep-name.git
- Changed or edited some files, and added them to the queue
$ git add filename.extension
- Committed and pushed them to server (wanted to override the master and kept the commit logs)
$ git commit -m “a message.”
$ git push origin master
But then returned some errors:
error: src refspec master does not match any.
error: failed to push some refs to ‘ssh://project-url/rep-name.git’
BTW, $ git push –force origin master didn’t work as well.
The solution was to use:
$ git push origin HEAD:<branch>
For this example, the <branch> was master:
$ git push origin HEAD:master
The problem was caused because of not initializing the branch before pushing. Another solution is to configure the default push location of the branch, such as:
$ git push –set-upstream origin refs/heads/the-remote-branch
But $ git push origin HEAD:<branch> method requires less types.
More information is at StackOverflow, although the first solution doesn’t work for me.