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

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'

当前回答

对我来说,这似乎是因为我已经完成了提交过程,所以我在尝试再次提交后得到了这个结果。

Your branch is ahead of 'origin/main' by 1 commit.
  (use "git push" to publish your local commits)

因为我看到路径是origin/main,所以我将其推到main而不是master,并且它起了作用。

注意:检查以确定主分支是主分支还是主分支。

截至2022年。

其他回答

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

为此,您需要按如下方式输入提交消息,然后推送代码:

git commit -m "initial commit"

git push origin master

已成功推送到主机。

最初,每个文件都处于未跟踪状态。我们需要将未跟踪的文件从工作目录添加到暂存区,只有这样Git才能开始跟踪这些文件。从工作目录中,我们将文件移动到准备好进行下一次提交的暂存区,这样Git就可以对它们进行快照以创建新版本。您跳过了临时区域,只向临时区域添加了一个文件。

首先转到要推送的本地文件夹,然后执行以下步骤。

初始化

git添加。

gitcommit-m“首次提交”

万一您在执行gitinit并推送初始提交后仍面临此问题。然后,您可以尝试以下操作:,

git checkout -b "new branch name"
git push origin "new branch name"

您的代码将作为新分支推送。

git add .

这就是你所需要的。该代码跟踪目录中所有未跟踪的文件。

我收到这个错误,因为我的本地分支名称与我试图使用git push origin创建的新远程分支不匹配。