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

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 branch
* version-x  # you are in this branch
  version-y

$ git push -u origin master
error: src refspec master does not match any.
error: failed to push some refs to 'origin_address'

我也遇到了同样的问题,并且发现我没有提交任何文件,所以当我再次尝试提交时,我收到了以下错误消息:

*** Please tell me who you are.

Run

 git config --global user.email "you@example.com"
 git config --global user.name "Your Name"

 to set your account's default identity.
 Omit --global to set the identity only in this repository.

 fatal: unable to auto-detect email address (got 'USER@WINDOWS-HE6I2CL.(none)')

然后我所做的就是在全球范围内添加我的电子邮件和姓名,然后再次提交:

git commit -m 'Initial commit'

然后按下

git push -u origin master

也许GitHub不知道你是谁。

首先,您必须运行:

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

在我的例子中,我克隆了一个存储库,但我没有切换到本地分支。

我通过这样做解决了这个问题:

在对代码进行更改之前,应执行以下操作:

git checkout branch-name

然后对代码进行更改

之后,将代码推送到分支:

git push -u origin branch-name

此外,如果您第一次将本地存储库推送到GitHub,则需要首先创建一个主分支:

git branch -M main

然后,在添加原点(或给遥控器取的任何名称)后,按下分支:

git push -u origin main

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

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