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

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的错误:

错误:src-refspec-master与任何不匹配。

已修复此步骤:

git commit -m "first commit"

在我跑步之前:

git add <files>

在我跑步后:

git push -u origin master

其他回答

此问题的另一个可能原因是您拼写错误了分支名称。因此,如果你做了我所做的,那么问题将通过纠正来解决:

git push origin mater

to

git push origin master

在我的例子中,出现在Windows上的问题似乎与我们在分支名称中添加前缀类似feature\有关。我们试图创建并推送一个具有这样前缀的分支(例如,feature\branch),但已经有一个不同的分支,其前缀为feature\(例如,feature\otherbranch)。这意味着在Windows上,新分支被放置在相同的refs\heads\Feature文件夹中。Git可能区分大小写,但Windows文件系统不区分大小写。一旦我们签出了名为Feature\branch的本地分支,它就起到了作用。

我在Android Studio中处理VCS时遇到了这个确切的问题。事实证明,我所要做的就是:

从“app”文件夹中选择所有文件;转到VCS(顶部选项);“添加”文件;通过终端或通过下拉菜单单击再次提交;推

尤里卡!:D

添加空目录时遇到此问题。Git不允许推送空目录。这里有一个简单的解决方案。

在要推送到远程的目录中创建文件.gitkeep,并从命令行提交“空”目录:

touch your-directory/.gitkeep
git add your-directory/.gitkeep
git commit -m "Add empty directory"

我也遇到了同样的问题,并且发现我没有提交任何文件,所以当我再次尝试提交时,我收到了以下错误消息:

*** Please tell me who you are.

Run

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

 to set your account's default identity.
 Omit --global to set the identity only in this repository.

 fatal: unable to auto-detect email address (got 'USER@WINDOWS-HE6I2CL.(none)')

然后我所做的就是在全球范围内添加我的电子邮件和姓名,然后再次提交:

git commit -m 'Initial commit'

然后按下

git push -u origin master