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

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 branch

查看分支。

其他回答

对我来说,只需签出我希望代码推送的分支,然后简单地推送您的代码。

git checkout -b branchname-on-which-i-will-push-my-code

git add .
git commit -m "my commit message"
git push origin branchname-on-which-i-will-push-my-code

您可能忘记了命令gitadd。在gitinit命令之后。

我在错误的目录中创建了文件,尝试执行git push-u origin master,但我得到了错误。

一旦我cd到当前目录,执行gitpush-uorigin-master,一切都很好。

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

*** 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

我错过跑步时也遇到了同样的问题:

git add .

(必须至少有一个文件,否则会再次出现错误。)