我使用以下内容克隆存储库:

git clone ssh://xxxxx/xx.git 

但在我更改一些文件并添加和提交它们之后,我想将它们推送到服务器:

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

但我得到的错误是:

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

当前回答

对我来说,以下操作可以移动未跟踪的文件:

git add --all

接下来,我遵循了类似的步骤

 git commit -m "First commit"

然后

git remote add origin git@github.....

最后但并非最不重要的是:

git push -u origin master

当您执行此操作时,Windows安全将弹出窗口,询问您的用户名和密码。

其他回答

我遇到了同样的问题,我使用了--允许空:

$ git commit -m "initial commit" --allow-empty
...
$ git push
...

补充

这个问题的一个主要原因是,在克隆新的存储库时,一些Git服务器(如BitBucket)没有初始化其主分支。

我有一个非常长的本地分行名称。

git branch -m new_shorter_branch_name

解决了问题。

如果您在Windows上使用GitBash,请尝试重新启动它。它对我有用!

我忘记在提交之后和推送之前执行“git pull-origin master”,这导致了同样的问题:“在git中推送提交时,src-refspec-master不匹配”。

因此,您应该做到:

1. git add .
2. git pull origin master
3. git commit -am "Init commit"
4. git push origin master

我也犯了类似的错误。但Git告诉我:

*** Please tell me who you are.

Run

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

或设置帐户的默认身份。

Omit --global to set the identity only in this repository.

然后错误消失。