Briefly:

Cause: The names of local and remote branches are not the same
Solution: git push remote_repo HEAD:remote_branch OR (suggested) git config push.default upstream

I’m currently working as an intern developer in an eHealth startup. They’re using the hosts from Aptible to provide their services to customers.

Aptible is generally a Docker (heroku) based hosting and every time when you push the code into a certain Git repository, which is corresponding to a container, Aptible will automatically deploy your new contents. And as we’ve got different environments, such as development, pre-production, production, I have to set up multiple remote repositories so that I can apply different Git branches to different applications.

However, despite of multiple remote repositories, names of remote branches are always “master”. So while pushing, I got

error: src refspec master does not match any.
error: failed to push some refs to 'git@example.com:username/whatever.git'

I Googled the error message and the solutions were all “before pushing, commit something in your EMPTY repository”, which was obviously not the reason of my error. Actually, it was caused by branch names mismatching between local and remote repositories. Rather than git push remote_repo master, git push remote_repo HEAD:master should be used, or simply git config push.default upstream to suppress the name check.