src refspec master does not match any when pushing

2018-12-31 07:51发布

I cloned my repository with:

git clone ssh://xxxxx/xx.git 

but after I changed some files and add and commit them I want to push them to server:

git add xxx.php
git commit -m "TEST"
git push origin master

But the error I get back is:

error: src refspec master does not match any.  
error: failed to push some refs to 'ssh://xxxxx.com/project.git'

标签: git commit
30条回答
琉璃瓶的回忆
2楼-- · 2018-12-31 08:16

This just mean you forgot to do the initial commit, try

git add .
git commit -m 'initial commit'
git push origin master
查看更多
忆尘夕之涩
3楼-- · 2018-12-31 08:19

Missing or skipping git add . or git commit may cause this error:

git push -u origin master
Username for 'https://github.com': yourusername
Password for 'https://yourusername@github.com': 
error: src refspec master does not match any.
error: failed to push some refs to 'https://github.com/yourusername/foobar.git'

To fix it, reinitialize and follow the proper sequence:

git init
git add .
git commit -m 'message'
git *create remote
git push -u origin master
查看更多
听够珍惜
4楼-- · 2018-12-31 08:19

In case if you are facing this problem even after doing git init and pushing your initial commit. You can the try the following,

git checkout -b "new branch name"
git push origin "new branch name"

Your code will be pushed as new branch.

查看更多
心情的温度
5楼-- · 2018-12-31 08:19

I faced same problem and I used --allow-empty.

$ git commit -m "initial commit" --allow-empty
...
$ git push
...
查看更多
旧时光的记忆
6楼-- · 2018-12-31 08:21

I think its because you pushed an invalid branch. Generally because the repository does not have common master branch(maybe development branch). You can use git branch to see branches.

查看更多
与君花间醉酒
7楼-- · 2018-12-31 08:23
  1. Try git show-ref to see what refs do you have. Is there refs/heads/master?

  2. You can try git push origin HEAD:master as more local-reference-independent solution. This explicitly states that you want to push the local ref HEAD to the remote ref master (see the git-push refspec documentation).

查看更多
登录 后发表回答