Git is a source-control tool used by software developers.
I recently switched from Subversion to Git and while things have been mostly smooth, there have been a few “WTF?” moments. I am going to try and blog the few beginner ones I ran into in hopes of helping anyone else.
Today I ran a ‘git push’ to shove my commits from my local repository back into the main remote repo, the result was this:
$ git push No refs in common and none specified; doing nothing. Perhaps you should specify a branch such as 'master'. error: failed to push some refs to 'git@github.com:painfreepr/<repo>.git'
The odd bit is that I had just done this with a previous repo about 30 mins ago and it worked fine; this was a new repository I was setting up. As it turns out this is the result of originally cloning an empty repository (link, link) which is exactly what I did. I had created a new repo on GitHub and wanted to pull the repo down in IntelliJ to then add some files to it via the GUI instead of from the command line; so I had checked out the empty repo right after creating it.
The fix, fortunately, is dead easy:
$ git push origin master
Doing this should provide output like:
$ git push origin masterCounting objects: 568, done.Delta compression using up to 2 threads.Compressing objects: 100% (559/559), done.Writing objects: 100% (568/568), 2.28 MiB | 2.18 MiB/s, done.Total 568 (delta 205), reused 0 (delta 0)To git@github.com:painfreepr/<repo>.git* [new branch] master -> master
It is my understanding that the core issue is that there are no files in common between the original remote repo you cloned (empty) and the one on-disk (now full of files). Doing the git-push-origin-master shoves your repo up into the empty repository and gives you that common base again so you can do a ‘git push‘ without issue.
Happy Git’ing!

Thanks for the tip – it worked, and you’ve just saved me some hassle!
Thanks for this. I would have been scratching my head for a while over this one…
James, glad we could help!
Thanks for helping me out!
Thank you, saved me a lot of time!
Thank you so much for posting this. It saved me a bunch of time. This is one of several really dumb design decisions in Git that just drive me batty.
They are not DUMB, its you that won’t spend some time learning it.
thanks, this helped!
Glad to hear it bp.
Thank you for this – Quick google search brought this up, and this fixed it
<3
Excellent, that’s exactly what I was hoping for.
Thank you. This was soo Useful!
Thanks, it worked for me. It’s really dead easy :p
I love your intro, “there have been a few WTF moments” since I switched from SVN to Git. I tried your fix and got:
error: src refspec master does not match any.
Still scratching my head; a portion of my skull is missing! Especially puzzled that I’m the only one for whom your dead easy fix did not work. Holler if the above error is familiar to anyone else!
Follow-up, in case I’m not the only person on the internet missing a portion of my skull. The answer, for me, came by literally just following the directions github provides for gits just like myself. DON’T clone the empty repository. Just go to your linux shell and try:
mkdir api-test
cd api-test
git init
touch README
git add README
git commit -m ‘first commit’
git remote add origin git@github.com:Wendr/api-test.git
git push -u origin master
haha, Nick thank you for the followup. I know it will help a number of folks that end up here via search that have scratched portions of their scalps away
Indeed, thank you
.
You saved my @ss thank man!
Shane, glad it helped!
Thanks for sharing,
such a simple issue when you know how, but kept me stumped for a while until I came across this post.
New to git and still getting my feet wet.
Thanks ..It helped me
Thanks very much, very helpful
Thanks for posting this. Had the same problem and the same fix worked.
Thanks a lot !! .. it really helped
Thanks!
you need a facebook like button to click it, thanks
It just worked for me too, thank!
Thank you. It works for me
Thanks
Helped me as well… thanks!
much appreciated… first link on the error message on google.
this is how programming with internet is suppose to be!!
Thanks a bunch! I’ve been scratching my head for the whole evening over this.
Cheers!
Awesome..
thanks it worked
Thanks, it really helped