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

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 init
git add .
git status
git commit -m "initial commit"
git remote add origin "github.com/your_repo.git"
git push --set-upstream origin master

其他回答

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

git add .

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

也许GitHub不知道你是谁。

首先,您必须运行:

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

在您从外部存储库(GitHub)中检出代码,并希望将其导入个人/内部系统的场景中,此命令非常有用:

git push --all origin

这会将所有本地分支推到远程,而无需检查ref,也无需坚持提交。

如果在分离HEAD模式下工作时出现此错误,可以执行以下操作:

git push origin HEAD:remote-branch-name

另请参见:从分离的头部推动Git

如果您所在的本地分支与远程分支不同,可以执行以下操作:

git push origin local-branch-name:remote-branch-name

试试看:

git add .

git commit -m "your commit message"

git remote add origin *remote repository URL*

git push origin *your-branch-name*