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

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'

当前回答

我曾经遇到过这个问题,因为我在远程回购上有一个分支,但不是本地的。我做到了:gitfetch&&gitcheckout‘在这里添加远程分支名称’,这解决了我的问题。有时,当您不准备更改时会出现问题,因此,要做到这一点,您需要运行以下git命令:git-add your_file_name.extension或git-add。添加所有更改。此时,您需要通过以下方式提交更改:gitcommit-m'您的提交消息在这里'。完成所有这些操作后,只需通过以下方式将更改推送到远程回购:git推送原点your_branch_name。

其他回答

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

并遵循以下步骤:

git init
git add .
git commit -m "message"
git remote add origin "github.com/your_repo.git"
git push -u 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

Github将默认分支名称从master更改为main。因此,如果您最近创建了回购,请尝试推送主分支

git push origin main

Github文章

截至2020年10月1日,GitHub正在将主分支的名称更改为main。这就是导致问题的原因。当有人键入git push origin master时,他们会看到此错误错误:src refspec master与任何错误都不匹配:未能将某些ref推送到'https://github.com/username/reponame.git'

这可以通过使用git push origin main来解决。希望这有帮助。我花了很长时间才弄明白为什么我不能将我的承诺提交给主分支。

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