@Marco That's not a duplicate. That one is a very specific issue about pushing a local branch to a remote branch. This one is about initializing a repo and pushing it up. They produce the same error, but the REASONS they produce that error and the fixes are entirely different. Also, sinoohe, you should accept an answer. Probably the first one, seeing as it answers the question and has helped over 350 people.
–
tandrewnicholsJul 8 '13 at 0:42

You just saved me Vi. Thank you for git push origin HEAD:master. But why something like git push --force origin master does not work?
–
shkschneiderJul 17 '12 at 14:09

2

@gms8994 -- you're correct. if someone creates a branch as a first thing instead of pushing into master, the same unfriendly error shows up. use git push origin <branch> instead of master in case you attempt to git checkout -b <branch> before any FIRST push after initial git remote add origin <url>
–
asyncwaitJul 6 '13 at 20:33

The other answers did not solve the problem I was having (for instance, I had already committed and still had this error), but doing a git push origin BRANCH --force worked. Thank you!
–
Lemmings19Mar 5 '13 at 1:35

See this earlier answer. I suspect that you needed to add a file because git won't track empty directories.
–
CupcakeApr 4 '14 at 20:57

Same here, would love to know why this was the case. Thanks for this solution to you and Vi.
–
Elijah LynnJan 9 '14 at 22:29

3

I finally found out that it was because I misspelled the branch name. I successfully pushed branch A to origin with a branch named B with git push origin HEAD:B, but I still got the same error every time when I push with git push origin on branch A.
–
Yi HuangFeb 17 '14 at 16:39

I had the same error message from git, and this was the solution., so it IS an answer to the question. Apparently this has helped a few people out, since a few people have upvoted it.
–
GavinApr 5 '14 at 15:25

I suspect a great many of us who came here via web search actually mistyped the name!
–
sageJun 23 '14 at 2:49

If you want to push your current branch, an easy way to do it is to simply do git push origin HEAD, or git push origin @ if you're using a recent version of Git, or git push origin head if you're using Windows or OS X.
–
CupcakeJun 17 '14 at 16:59

I came across this issue when I forgot that I renamed the master branch
–
RobotEyesDec 17 '14 at 17:27

I was contributing to one github repo so I forked the project, cloned it, created my own branch, did some commits and tried to push. At this point I discovered that I cloned not my fork but the original project repo (which I don't have permission to push).

So I changed the .git/config to point origin to my repo.

at this point when I tried to push I was getting error error: src refspec my_awesome_branch does not match any.

All I had to do is to touch any file and commit it (similar like you see it in this answer

This just happened to me. Something in my env was off (I think due to a borked rebase, but I'm not sure). Closing my terminal (OSX 10.8.3 / Zsh) and opening a new one fixed it. Always try turning it off and on again!

@Aryo In my case I had to use the full url of my local git repository to push the file. First I removed all the files in current directory. Created README added it. Added some more. Then I commited those files and at last pushed them giving proper url to the repository. Here yourrepository is the name of the repository in the server.