Git Tip: git push ‘No refs in common and none specified’

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 master
Counting 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!

Tags: , , , , , ,

About Riyad Kalla

Software development, video games, writing, reading and anything shiny. I ultimately just want to provide a resource that helps people and if I can't do that, then at least make them laugh.

, , , , , ,

40 Responses to “Git Tip: git push ‘No refs in common and none specified’”

  1. James June 14, 2010 at 1:55 am #

    Thanks for the tip – it worked, and you’ve just saved me some hassle!

  2. James July 1, 2010 at 2:29 pm #

    Thanks for this. I would have been scratching my head for a while over this one…

  3. Mikko November 11, 2010 at 2:45 pm #

    Thanks for helping me out!

  4. René February 17, 2011 at 8:53 am #

    Thank you, saved me a lot of time!

  5. CXJ April 5, 2011 at 9:21 am #

    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.

    • Johan August 31, 2012 at 6:17 am #

      They are not DUMB, its you that won’t spend some time learning it.

  6. bp August 23, 2011 at 11:31 am #

    thanks, this helped!

  7. Cal Leeming September 15, 2011 at 12:48 pm #

    Thank you for this – Quick google search brought this up, and this fixed it :) <3

    • Riyad Kalla September 17, 2011 at 9:23 am #

      Excellent, that’s exactly what I was hoping for.

  8. aerozeppelin November 11, 2011 at 2:29 pm #

    Thank you. This was soo Useful!

  9. Ken Lai November 16, 2011 at 7:28 pm #

    Thanks, it worked for me. It’s really dead easy :p

  10. Nick Kaye November 23, 2011 at 10:56 pm #

    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!

  11. Nick Kaye November 23, 2011 at 10:59 pm #

    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

    • Riyad Kalla November 24, 2011 at 6:07 am #

      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 :)

      • nik January 24, 2012 at 9:10 am #

        Indeed, thank you :) .

    • Ahmed November 18, 2013 at 4:52 am #

      Awesome Nick! Thank you so much – was banging my skull for a long time :)

  12. Shane February 2, 2012 at 8:55 am #

    You saved my @ss thank man!

  13. Andrew Waite February 28, 2012 at 10:13 am #

    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.

  14. Ramya March 12, 2012 at 10:19 am #

    Thanks ..It helped me

  15. Sean March 20, 2012 at 10:33 am #

    Thanks very much, very helpful

  16. Juhani April 5, 2012 at 3:01 am #

    Thanks for posting this. Had the same problem and the same fix worked.

  17. berry May 5, 2012 at 1:53 pm #

    Thanks a lot !! .. it really helped

  18. Dario May 19, 2012 at 4:22 pm #

    Thanks!

  19. jaime June 3, 2012 at 2:08 pm #

    you need a facebook like button to click it, thanks

  20. Andrea Grandi June 12, 2012 at 12:44 am #

    It just worked for me too, thank!

  21. JaredYe July 20, 2012 at 1:45 am #

    Thank you. It works for me

  22. AW September 2, 2012 at 10:23 pm #

    Thanks

  23. rich September 10, 2012 at 6:43 am #

    Helped me as well… thanks!

  24. evanthebouncy November 12, 2012 at 10:35 pm #

    much appreciated… first link on the error message on google.
    this is how programming with internet is suppose to be!!

  25. Espen pling plong November 23, 2012 at 8:30 am #

    Thanks a bunch! I’ve been scratching my head for the whole evening over this.

    Cheers!

  26. pravsim December 7, 2012 at 4:29 am #

    Awesome..
    thanks it worked

  27. Sharma December 17, 2012 at 12:26 pm #

    Thanks, it really helped :)

  28. Jeff Gardner June 13, 2013 at 9:02 pm #

    Awesome. Glad to know I’m not the only one who was stuck!

  29. Guilherme October 21, 2013 at 9:14 pm #

    Thank man!

  30. Sasha November 2, 2013 at 10:08 am #

    TY

Trackbacks/Pingbacks

  1. Git: git push -> No refs in common and none specified; doing nothing | Mitchell Fang's Coding - February 13, 2013

    [...] thebuzzmedia [...]

  2. git: some tricks | A sysadmin's logbook - May 21, 2013

    [...] took some time and research to find out that the solution is a [...]

Leave a Reply


2 + 2 =