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

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 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

其他回答

我犯了这个错误,

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

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

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

可能是您当前的分支没有上游分支。当你要第一次按下时,请尝试这些命令。

git init
git add .
git status
git commit -m "initial commit"
git remote add origin "github.com/your_repo.git"
git push --set-upstream origin master
git init
git add .
git commit -m "message"
prompt me to enter email and user name
  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

输入上述详细信息后,文件将提交并成功推送:

git push

面临的问题

当我在GitHub上创建一个新的存储库并将其与我的客户端计算机上的react应用程序链接时,我也遇到了同样的问题。

我使用了以下步骤:

出现问题之前使用的命令

git init
git commit -m "first commit"
git branch -M main
git remote add origin "_git repository link here_"
git push -u origin main

我的错误

但正如你所见,我的错误是没有使用gitadd。命令我犯了这个错误,因为我已经有了README.md文件,而GitHub在创建存储库时会指导我们使用基本命令。

我的解决方案

我的解决方案是使用gitadd。gitinit命令之后。

按照相同的顺序使用以下命令集来解决问题:

git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin "_git repository link here_"
git push -u origin main

我的分支名为bugfix-22112022/5v8ST5Q6/181 kontaktformular eingabe nach anmeldung-übernehmen,<--是的,它有一个逗号,我认为逗号不是它的一部分,并在尝试推送时删除了它。。。

我重命名了我的分支:

git branch -m bugfix-22112022/5v8ST5Q6/181-kontaktformular-eingabe-nach-anmeldung-übernehmen