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

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 push origin master,但当我键入git branch时,我是在v1分支上,所以我必须键入git pushorigin v1。

其他回答

来自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 clone -b new-branch
$ git push origin new-branch

2021,GitHub将默认分支名称更改为main。以前它是主人。

我之所以痛苦,是因为我试图向不存在的主服务器推送,而远程的分支是主服务器。确保您使用的分支名称正确。

下面的命令对我有效

git push origin main

在我的例子中,fastlane match nuke开发(它从git凭证存储和开发者门户中删除开发证书和配置文件)试图推送master,但我们没有master。由于我们有两个不同的团队,我们也有两个分支机构。解决问题的方法是打电话告诉match正确的分支:

fastlane match --git_branch <your_branch> nuke development