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

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'

当前回答

我为一个GitHub存储库做了贡献,所以我分叉了这个项目,克隆了它,创建了自己的分支,进行了一些提交,并尝试推送。

此时,我发现我克隆的不是我的fork,而是原始的项目存储库(我没有权限将其推送到)。

所以我更改了.git/config以将原点指向我的存储库。

此时,当我尝试推送时,我收到了错误消息:src-refspec my_awesome_branch不匹配。

我所要做的就是触摸任何文件并提交它(就像你在这个答案中看到的一样):

git touch README
git commit -m "fixing error in my git repo"

然后:

git checkout master
git pull origin master
git push origin master # This will tell my remote repository about my new branch
git checkout my_awesome_branch
git push origin my_awesome_branch # Now it will work

其他回答

git push -u origin master
error: src refspec master does not match any.

为此,您需要按如下方式输入提交消息,然后推送代码:

git commit -m "initial commit"

git push origin master

已成功推送到主机。

检查提交标题,因为如果忘记了gitcommit-m“xxxx”命令,就会遇到同样的问题

git commit -m "initial commit"

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

并遵循以下步骤:

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

确保先添加,然后提交/推送:

喜欢:

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

我有一个非常长的本地分行名称。

git branch -m new_shorter_branch_name

解决了问题。