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

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'

当前回答

更新答案:确保所有更改都已提交。

然后键入:gitpush在这之前,请确保创建一个个人访问令牌,GitHub现在使用这个。然后键入您的GitHub用户名(键入gitpush后),然后将您的个人访问令牌粘贴到密码输入中。

所有这些之后,您应该可以在GitHub中看到您的更改!

其他回答

我也面临同样的问题。在我的案例中,我在添加之前犯了错误。按顺序执行这些步骤后,我得到了它。

此外,请确保提供正确的分支名称。

git init
git add .
git commit -m <Your commit message>
git remote add origin "your repository link here"
git push -u origin master

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

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

在删除本地计算机上的所有文件后,我也出现了类似的错误,我必须清理存储库中的所有文件。

我的错误消息如下:

error: src refspec master does not match any.
error: failed to push some refs to 'git@github ... .git'

通过执行以下命令解决了问题:

touch README
git add README

git add (all other files)
git commit -m 'reinitialized files'
git push origin master --force  # <- caution, --force can delete others work.

同时检查是否更改了分支名称

对我来说,我已经将分支名称从添加状态条件更改为添加状态条件,但没有注意到末尾缺少的s。正确重命名了分支,git推送原点添加了状态条件-f。

这对我有用。

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

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