频道栏目
首页 > 资讯 > 其他 > 正文

git+idea出错 | Push rejected: Push to origin/master was rejected如何解决?

18-03-26        来源:[db:作者]  
收藏   我要投稿

背景:我是在学习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/'

原因是因为你的配置文件没有用户名和密码的配置,所以你需要重新输入一下,如果你觉得麻烦,可以直接在配置文件中进行配置。

相关TAG标签
上一篇:部署虚拟机环境安装Centos7教程
下一篇:Shell编程之sed命令详细介绍
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站