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

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

其他回答

我也有同样的问题。我通过以下步骤做到了这一点:

1. git commit -m 'message'
2. git config --global user.email "your mail"
3. git config --global user.name "name"
4. git commit -m 'message'
5. git push -u origin master

几天前我也遇到过同样的问题。

如果您现在(2020年)创建了一个新的存储库,那么默认分支是GitHub上的main。

您现在可以在存储库分支中查看GitHub。

您还可以通过运行以下命令检查终端中的分支:

git branch

所以这就是你需要跑步的原因

git push origin main

而不是

git push origin master

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

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

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

fastlane match --git_branch <your_branch> nuke development

2021 3月,Git 2.31:

空GitHub存储库的git克隆将创建一个本地存储库,其中“main”作为默认分支,即使在master上设置了init.defaultBranch!

GitHub支持的Git transfert协议v2将向客户端传递Git clone创建的本地Git存储库的远程默认分支(现在是GitHub的主分支)的名称。

这意味着添加和提交新的提交将在“main”分支上完成,即使Git客户端仍然将master作为默认分支。

下一次推送时,不再出现“src-refspec-master不匹配任何”。