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

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'

当前回答

我犯了这个错误,

错误:src-refspec-master与任何不匹配。

当我试图将提交推送到GitHub时,发生了变化(在GitHub)。

git push -u origin branch-name - helped me to get my local files up to date

其他回答

试试看:

git add .

git commit -m "your commit message"

git remote add origin *remote repository URL*

git push origin *your-branch-name*

git push-u原始主机

error: src refspec master does not match any.
error: failed to push some refs to 'http://REPO.git'

这是由于存储库仍然是空的。存储库中没有提交,因此没有主分支可以推送到服务器。

这对我有用

决议

1) git init
2)git commit -m "first commit"
3)git add app
4)git commit -m "first commit"
5)git push -u origin master

首先,您需要gitinit来创建您自己的.git文件,否则如果您克隆了某个git文件夹,它将无法识别您的git凭据。启动git后,继续执行gitadd。和gitcommit。。。

我今天也遇到了同样的问题。我创建了一个新的repo并将其克隆到我的机器上。我提交了我的代码并尝试推送它。我也收到了同样的错误。我观察到这是因为我在使用:

git推送原始主机

我在这里做错的是,我假设我的默认分支是master,而GitHub上的新默认分支是main。我推送时使用:

git推送原点主

而且效果很好。

我的解决方案只适用于最近面临这个问题的较新的repo或用户,因为GitHub正在取代主要的over-master术语。因此,如果您收到此错误,请确保检查要推送到的分支以及GitHub上的分支名称。

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

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

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

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

截至2022年。