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

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创建的新远程分支不匹配。

其他回答

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

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

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

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

截至2022年。

同时检查是否更改了分支名称

对我来说,我已经将分支名称从添加状态条件更改为添加状态条件,但没有注意到末尾缺少的s。正确重命名了分支,git推送原点添加了状态条件-f。

这对我有用。

要检查当前状态,请使用gitstatus。

并遵循以下步骤:

git init
git add .
git commit -m "message"
git remote add origin "github.com/your_repo.git"
git push -u origin master

作为解决问题的选项之一:

git push origin HEAD

更新答案:确保所有更改都已提交。

然后键入:gitpush在这之前,请确保创建一个个人访问令牌,GitHub现在使用这个。然后键入您的GitHub用户名(键入gitpush后),然后将您的个人访问令牌粘贴到密码输入中。

所有这些之后,您应该可以在GitHub中看到您的更改!