我克隆了我的存储库:
git clone ssh://xxxxx/xx.git
但在我改变了一些文件之后 add
和 commit
他们我想将它们推送到服务器:
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 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.
就是这样,希望这会有所帮助。
- 我的更改已经提交
- 强制推动仍然给了我同样的错误。
所以我试过了 Vi的解决方案:
git push origin HEAD:<remoteBranch>
这对我有用。
对我来说,我必须确保 公钥 在服务器中正确配置(附加在〜/ .ssh / authorized_keys中)和github / bitbucket(添加到我在github或bitbucket上的SSH密钥) - 它们需要匹配。
然后:
git add --all :/
git commit -am 'message'
git push -u origin master
最后为我工作。
缺少或跳过 git add .
要么 git commit
可能会导致此错误:
git push -u origin master
Username for 'https://github.com': yourusername
Password for 'https://yourusername@github.com':
error: src refspec master does not match any.
error: failed to push some refs to 'https://github.com/yourusername/foobar.git'
要修复它,请重新初始化并遵循正确的顺序:
git init
git add .
git commit -m 'message'
git *create remote
git push -u origin master
在git只添加了一个目录后,我发现这发生在一个全新的存储库中。
一旦我添加了一个文件(例如README),git push就能很好地工作。