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

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'

当前回答

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

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

成功

其他回答

权限问题?解决方案:分叉

我收到这个错误是因为我没有对存储库的推送权限,所以我不得不分叉它,然后我在分叉的存储库上再次执行了pull、commit和push命令。

我走错了路。检查您的分支。我在“主”分支而不是“主”。

git分支使用-mv标志重命名分支:git分支-mv源主机

在这个git分支之后应该显示master

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

对我来说,只需签出我希望代码推送的分支,然后简单地推送您的代码。

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