Push rejected: Push to origin/master was rejected
背景:我是在学习android的时候,遇到的这个问题,我在androidstudio写完代码,运行完demo后,利用git进行commit and push 的时候出现的这个错误 解决方法:你需要从VCS中的git中pull一下你github中初始化的空仓库,但是你执行VCS->Git->pull也是会报错的,错误如下:
Git Pull Failed: fatal: refusing to merge unrelated histories
意思是git拒绝合并两个不相干的东西 此时你需要在打开Git Bash,然后进入相应的目录,然后敲git命令:
$ git pull origin master --allow-unrelated-histories
出现类似于这种信息就说明pull成功了:
From https://github.com/danishlyy/HappyBirthday * branch master -> FETCH_HEAD Merge made by the recursive strategy. README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 README.md
然后你可以利用git status查看一下当前仓库的状态,是不是所有的全部add并且commit,如果全部完成,那么此时你就可以将本地仓库中的推送到github中,使用如下的git命令:
$ git push -u origin master
完了,去刷新github,就可以看到东西已经推送成功 注意: 可能你在推送的过程中会遇到问题
fatal: AggregateException encountered. ▒▒▒▒һ▒▒▒▒▒▒▒▒▒▒ Username for https://github.com: remote: Anonymous access to danishlyy/HappyBirthday.git denied. fatal: Authentication failed for https://github.com/danishlyy/HappyBirthday.git/
原因是因为你的配置文件没有用户名和密码的配置,所以你需要重新输入一下,如果你觉得麻烦,可以直接在配置文件中进行配置。
上一篇:
通过多线程提高代码的执行效率例子
下一篇:
生命之树 (搜索 || 树形DP)