Git Push Error: src refspec master does not match any

Two possible causes:

  1. Cloned the repository with
    $ git clone ssh://project-url/rep-name.git
  2. Changed or edited some files, and added them to the queue
    $ git add filename.extension
  3. 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.

Leave a Reply

Time limit is exhausted. Please reload CAPTCHA.