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

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'

当前回答

首先,确保您使用的是master分支。在我的案例中,分支是主分支而不是主分支。所以我做的是

git push origin main

你可以在这张照片中看到结果

其他回答

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

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

成功

我面临着类似的错误。错误是由此命令引起的

git push -u origin master

随后的命令对我有效

从以下命令开始

git init
git add .
git commit -m "second commit"

所以在推送它之前,运行这些命令,看看我们的本地存储库连接到Github上的哪个远程存储库,以及您所在的分支。

git remote
git branch

远程-->原点

分支-->主

git push -u remote branch

或更具体地:

git push -u origin main
 sudo git push -v --progress "origin" : origin/prod_18aug2022

当我从本地分支机构推到远程分支机构时,这对我很有用。

这个问题主要有两种可能性。让我们逐一考虑一下。

可能是错误,主分支甚至不存在。在我的例子中,它被命名为main,而不是master。在这种情况下,您需要用main替换master。您甚至还没有提交更改。如果是这种情况,请转到-->

git添加。gitcommit-m“初始提交”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