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

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

其他回答

关于Aryo的回答:在我的情况下,我必须使用本地Git存储库的完整URL来推送文件。首先,我删除了当前目录中的所有文件,并创建了README。

添加了更多内容。然后我提交了这些文件,最后推送了它们,给了存储库一个正确的URL。这里,您的存储库是服务器上存储库的名称。

rm -rf *

touch README
git add README
touch file1 file2
git add file1 file2

git commit -m "reinitialized files"
git push git@localhost:yourrepository.git master --force

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

git branch -m new_shorter_branch_name

解决了问题。

如果您尝试推送的分支名称中有拼写错误,也会发生这种情况。

这对我有用,将存储库重置为远程主存储库:

git checkout master
git commit -a -m "your comment"
git push origin master

也许你只需要承诺。当我这样做的时候,我遇到了:

mkdir repo && cd repo
git remote add origin /path/to/origin.git
git add .

哎呀!从未承诺!

git push -u origin master
error: src refspec master does not match any.

我所要做的就是:

git commit -m "initial commit"
git push origin main

成功